In my editor, I have disabled the NumLock key by handling the keydown message as follows (pseudocode):
.if uMsg==WM_KEYDOWN && wParam==VK_NUMLOCK
invoke GetKeyState, ebx
test al, 1
.if Zero?
invoke keybd_event, ebx, 0, KEYEVENTF_KEYUP, 0 ; first, release the key
invoke Sleep, 1
invoke keybd_event, ebx, 0, 0, 0 ; second, trigger a second keypress to toggle
.endif
The logic is as follows:
- numlock is being pressed by user
- we catch the keydown message
- we insert a keyup message for the same key
- then we insert a keydown message
- and Windows completes the whole cycle by handling the keyup message.
This cheats the message queue by inserting keyup and keydown:
keydown ; windows
keyup ; handler
keydown ; handler
keyup ; windows
Result: the key can't be activated.