Reading a keystroke in a Console app

  • Thread starter Thread starter Brian Schwartz
  • Start date Start date
B

Brian Schwartz

I'm writing a console application. Both Read and ReadLine wait for enter to
be pressed before returning. Isn't there a way to read a single character
and continue immediately, without waiting for enter?
 
Brian,

In .NET 2.0., the Console class has a static ReadKey method which you
can use to read a key from the console.

In .NET 1.1, you could probably call the ReadConsoleInput API function
through the P/Invoke layer to get a similar effect.

Hope this helps.
 
Brian Schwartz said:
I'm writing a console application. Both Read and ReadLine wait for enter
to
be pressed before returning. Isn't there a way to read a single character
and continue immediately, without waiting for enter?

http://www.ai.uga.edu/mc/Konsole.zip

I implemented a Turbo Pascal-style console and keyboard interface. Feel
free to use it or learn form it.
 
Back
Top