Detecting a key press

When I say a key press I mean so it detects it as being pressed and not held down.

So GetAsyncKeyState isn't what I'm looking for, but along those lines.

I hope you understand what I mean
Windows sends a WM_KEYDOWN message to your window when that happens.

Or, if you are not using windows messages, you can still use GetAsyncKeyState, just keep track of it's previous state:

1
2
3
4
5
6
7
8
9
10
11
bool keypressed;
bool keydown;

// do this every 'frame' or every time you update:
bool tmp = GetAsyncKeyState( whatever );
if( !keydown && tmp )      // key wasn't down previously, but now is down
  keypressed = true;       // so it was just pressed
else                       // otherwise, it was not just pressed
  keypressed = false;

keydown = tmp;
Topic archived. No new replies allowed.