PDA

View Full Version : Retrieve the state of specific keys



Windsoarer
25th January 2009, 10:05
Another question: While the mouse is moved, is there a way to know if a keyboard key such as A or 'X' is down (pressed) ?

OK, it can be done by tracking the keyPress and keyRelease events, but it would be more convenient to just retrieve the keyboard state at any point in the program.

Any clues ?

Thanks

wysota
25th January 2009, 11:43
Note that at any point in time an arbitrary number of keys can be pressed. It would be hard and unusable to report the state of over 100 keys. You should track keyPress and keyRelease events yourself, don't be too lazy, it's just 6 lines of code in implementation and three lines of code in the header file.

Windsoarer
25th January 2009, 12:29
Well, thanks, I thought, or feared, that this might be the case.

I'm coming from the MFC world, where there is the very convenient GetKeyState(key) function. My experience, still in the MFC world, is that keydown and keyup messages get lost occasionally, so that it's safer to ask the keyboard state when you need it.

I'll try to track keypress and keyrelease events, and see how it goes.