473,508 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading a keystroke in a Console app

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 Schwartz
FishNet Components
http://www.fishnetcomponents.com
Try the best free grid available anywhere - no strings attached!

Nov 17 '05 #1
3 3025
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brian Schwartz" <br***@fishnetcomponentswos.com> wrote in message
news:eH*************@TK2MSFTNGP15.phx.gbl...
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 Schwartz
FishNet Components
http://www.fishnetcomponents.com
Try the best free grid available anywhere - no strings attached!

Nov 17 '05 #2

"Brian Schwartz" <br***@fishnetcomponentswos.com> wrote in message
news:eH*************@TK2MSFTNGP15.phx.gbl...
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.
Nov 17 '05 #3
Check out the ConsoleEx.dll from
http://www.gotdotnet.com/Community/U...b-0489938aae0f

Scott
"Brian Schwartz" <br***@fishnetcomponentswos.com> wrote in message
news:eH*************@TK2MSFTNGP15.phx.gbl...
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 Schwartz
FishNet Components
http://www.fishnetcomponents.com
Try the best free grid available anywhere - no strings attached!

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6215
by: hokieghal99 | last post by:
Does anyone know of a keystroke logger that has been written in Python for Windows machines? I'd like to see such a script and use it as a point of reference for a real-time backup project that I'm...
2
3218
by: Wayne Wengert | last post by:
I want to get the decimal (integer) value of user keystrokes. I am using the following code. chrInput is the character entered (e.g. "M") and "keystroke is DIMed as Short keystroke =...
15
5725
by: Frank Bormann | last post by:
Hi, probably a stupid question, but I haven't been able to find anything. Is there a istream related function that let me read exactly one keystroke from the keyboard through cin? What I...
3
1452
by: GG | last post by:
I have a console app that when it is run and I press a key then it freezes till a press another key gain. Is there a way to avoid it that is the keystrokes do not pause the app? Thanks ...
5
4783
by: Aaron | last post by:
In a console based application, I'd like to pause for a keystroke. I thought Console.Read would do the trick, but after it didn't I found this on the MSDN description of the function: ...
21
13025
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
2
2003
by: John Salerno | last post by:
I wrote this code just to experiment with writing to and reading from a file. It seems to work fine when writing, but when reading the file, it only prints the filepath to the screen, not the file...
3
1786
by: MLH | last post by:
Suppose I wanna type 12345 into a texbox on a form. After each keystroke, can I read 1, then 12, then 123 then 1234 and finally 12345? If so, how is this done?
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.