Reading a keystroke in a Console app


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?
 
Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

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.
 
M

Michael A. Covington

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.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top