Monday, 9 September 2013

Why is the dwControlKeyState of the pressed key does not match constant?

Why is the dwControlKeyState of the pressed key does not match constant?

I'm trying to handle the keypress event of the console in Windows 7. When
I'm press a left ctrl key i'm expecting to get code 0x0008 (0b00001000 -
LEFT_CTRL_PRESSED), but instead of this i'm getting 0x0028 (0b00101000).
...
DWORD n;
INPUT_RECORD ir;
HANDLE hin;
hin = GetStdHandler(STD_INPUT_HANDLE);
...
ReadConsoleInput(hin, &ir, 1, &n)...
...
if(ir.Event.KeyEvent.dwControlKeyState == LEFT_CTRL_PRESSED) {
// some code..
}
if using xor 32 all works fine:
if((ir.Event.KeyEvent.dwControlKeyState ^ 32) == LEFT_CTRL_PRESSED) {
// some code..
}
Where did the extra bits?
p.s.: project in unicode

No comments:

Post a Comment