-
March 19th, 2004, 01:13 AM
#1
How can I trap a keypress in C++?
Hello everyone,
I would be really grateful is someone could tell me how to trap a keypress in C++?I want to do a particular thing unless the user presses the enter key(or any key for that matter)..On detecting the keypress I want to move on and do something else..I tried the getch() method..But on doing that,it waits everytime for a keypress..which is not what I want...What I want is that the execution should proceed till the user presses a particular key...Any help would be highly appreciated.
Thanks.
-Ekta
-
March 19th, 2004, 08:57 AM
#2
The following should theoretically work:
Code:
char c;
while ( ! cin.readsome( &c, 1 ) ) {
// Do what you want to do
}
However you will run across the problem of buffering, which means that the input buffer will not actually contain any data untill the user has pressed return.
Getting an actual key press can be very OS dependant. And you haven't told us which OS and which environment (console app, some graphical toolkit) you use.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|