PDA

View Full Version : Keystrokes in C++


jokrswild
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.

KFB
04-22-02, 09:51 PM
#include <iostream.h>
char x;
cin >> x; // or x = cin.get();
cout << x << endl;

try cplusplus.com (http://www.cplusplus.com) for info.

jokrswild
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....

KFB
04-22-02, 10:11 PM
oh. i didn't understand. sorry.

jokrswild
04-22-02, 10:43 PM
no need to be sorry! i probably worded it weird. lol

Istari1
04-22-02, 11:38 PM
I believe
x = getchar();

will just wait for a keystroke.

Josh

Bmxpunk86pl
04-23-02, 02:56 PM
yea use the getchar() function