473,668 Members | 2,616 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 3032
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 ReadConsoleInpu t API function
through the P/Invoke layer to get a similar effect.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Brian Schwartz" <br***@fishnetc omponentswos.co m> wrote in message
news:eH******** *****@TK2MSFTNG P15.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***@fishnetc omponentswos.co m> wrote in message
news:eH******** *****@TK2MSFTNG P15.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***@fishnetc omponentswos.co m> wrote in message
news:eH******** *****@TK2MSFTNG P15.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
6220
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 working on. Basically, I'd like to be able to capture all keystrokes from the keyboard buffer and write them to a text file so I could reporduce emails, documents, etc. in the event of file loss that occurs between nightly backups. For example,...
2
3237
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 = Microsoft.VisualBasic.Val(chrInput) but it always yields a value of 0 How should I be doing this?
15
5739
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 need it to do is this: - remove all characters currently in the input buffer - block until the user presses a key
3
1456
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 *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
5
4795
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: Console.Read This method will not return until the read operation is terminated; for example, by the user pressing the enter key.
21
13077
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 server is on one line (\r\n at end) and is formed as - each of which is seperated by a space. Arguments with spaces in them are enclosed in quotations. So, I'm able to open a connection to the server. When I send a message to
2
2007
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 contents. System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\positions.txt"); System.IO.StringReader myFile = new System.IO.StringReader(@"C:\positions.txt"); for (int i = 0; i < 3; i++)
3
1793
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
8367
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7391
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2781
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 we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.