I started making use of Win32's raw input features to detect all keys on the keyboard. So far, everything is working great! I can distinguish between numbers on the top row and numbers in the keypad on the right. I can even detect between the left and right shift keys. However, the control and alt keys do not return unique scan codes. The control key returns 29, and the alt key returns 56.
The popular method for checking key states on these keys is GetAsyncKeyState
. I have tested that function using VK_LCONTROL
and VK_RCONTROL
, and it works, but that only helps me for capturing key down events. I would really like to be able to capture key up events as well. It is obvious that the API is somehow aware of which key is being pressed; how do I get ahold of that information?
I am currently extracting the scan code from the RAWKEYBOARD
structure's MakeCode
field. That gives me information about every key (and its left/right alignment) except CTRL and ALT. How would I go about capturing the key up events (and knowing whether it is left/right)? Is it possible using just the RAWKEYBOARD
structure? Or do I have to concoct some kind of workaround?
GetAsyncKeyState
is intended to give you a snapshot of the keyboard's state. It's not intended to tell you when things change. That's what theWM_KEYDOWN
,WM_SYSKEYDOWN
,WM_KEYUP
andWM_SYSKEYUP
events are for. I don't see why you call this inconsistent. They're two fundamentally different things. – ShirkerGetAsyncKeyState
inconsistent; I was referring to the way the scan codes are passed via raw input. – FascineRAWKEYBOARD::Flags
field work for you for CTRL/ALT if it works for other keys? – SofiaWM_KEYDOWN
andWM_KEYUP
contains both a scan code and an extended bit which helps determine right/left control key. However, the alt key remains elusive. – Fascine