If you hold a Numpad key(s) (e.g. numpad7), then press num lock, then release the Numpad key (numpad7), GetKeyState() and GetAsyncKeyState() both say that the key(s) (numpad7) is still pressed.
Seems like a key-up event is never sent to windows, so it thinks it is still pressed, but..... the key is not artificially held down in text inputs (renaming files, notepad, google search), and works as expected.
For context, I am making a small interactive app that reacts to a user's keypresses (animates someone typing). On the off chance someone presses a Numpad key and num lock at the same time, my app breaks (plays the wrong animation, as it thinks a key (or keys) are still pressed).
My question is: how do I stop or circumvent this behavior?
A simple demo:
#include <windows.h>
#include <winuser.h>
while (true)
{
for (int keycode = 8; keycode <= 222; keycode ++) {
if (GetAsyncKeyState(keycode ) & 0x8000)
{
cout << keycode << " ";
}
}
cout << endl;
}
The output would be something like:
36 //numpad7 held, with numlock ON
36 144 //numpad7 still held, numlock now tapped (toggled to OFF)
36 //numpad7 released, but it says it held (this shouldn't be possible as numlock is OFF, should be the keycode for home or something, if that physical key was pressed)
36 //still says it's pressed
36 //...