Reading console input w/o needing to press CR

basdewaard

Member
Joined
Dec 31, 1969
Messages
16
Location
Perth, Western Australia
Im struggling with something that I thought would have been relatively simple. Id like the user to enter a character into the console and have the console read it w/o the user having to press <enter>. ie: as soon as the user types a character, have the console read it.

I thought the following would help but it hasnt:

C#:
                //read the input...
                do {
                        ch = (char) Console.Read(); //get the char
                } while(ch == \n || ch == \r);
 
Last edited by a moderator:
Thanks for the link, divil, however I am not finding it easy to get going.

After reading readme files I opened the .sln (assuming running the project would link with the existing Console). The ConsoleExTest works (which was initially set as the Startup Project). I then tried to get ConsoleEx going but get an error along the lines of "A project with an Output Type of Class Library cannot be started directly". The message contained more information/suggestions which I tried w/o any luck.

I also tried to add (relevant) classes to my project but struggled.

Could you perhaps give me a rough idea of how I should go about tackling this?
 
Youd compile it to a class library, then reference that dll from your other project. I havent actually used the class myself, so I cant be a lot more help than that at the moment.
 
Back
Top