View Full Version : Keystrokes in C++
04-22-02, 07:49 PM
Does anyone know how to register a keystroke in C++? I want to setup a loop, waiting for a keystroke, then depending on the keystroke do something. Kinda like the arrow keys in video games. You'll know what i'm talking about if you've programmed in TI-BASIC using the getkey command.
cin >> x; // or x = cin.get();
cout << x << endl;
try cplusplus.com (http://www.cplusplus.com) for info.
04-22-02, 10:06 PM
but cin >> x reqires the user to hit enter after keying in whatever they want...
I'll try x=cin.get(), but i think it's the same thing. I want the keystroke to be registered (like an arrow key) without hitting enter....
oh. i didn't understand. sorry.
04-22-02, 10:43 PM
no need to be sorry! i probably worded it weird. lol
04-22-02, 11:38 PM
x = getchar();
will just wait for a keystroke.
04-23-02, 02:56 PM
yea use the getchar() function
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.