-
Passive Keyboard Input
I have used cin to get keyboard input for variables, getch() for getting single keypress information, but all of those cause the computer to wait for a keypress. I would like to have some kind of getch() like function that not "pause" the program. I would find this very useful for real-time DOS games.
-Zagaberoo
-
If your compiler supports it, you may be able to use the kbhit function.
-
kbhit?
what is kbhit? what header does it require? how is it used?
-
kbhit() question
kbhit() is a nifty little function, but can you make it useful, like getch()? I would really like to make a real-time game and need some kind of passive keyboard input that does not "pause" my program. kbhit() is cool, but can you have it input to a char or string? If not, what function or other helpful thingy can I use?
***PROGRAM IS IN DOS***
-Zagaberoo
-
Pointless poll closed, and threads merged
Try to be more careful when posting
It goes like this
Code:
// key pressed?
if ( kbhit() ) {
ch = getch(); // yes, read it
msg[n++] = ch;
msg[n] = '\0'; // add to line so far
if ( ch == '\r' ) { // end of line?
process(msg); // yes, figure out what it means
n = 0;
}
}
// do stuff which can't wait
-
There is no portable way to do it. You have to rely on compiler-specific code. What compiler are you using?