Reading here: How is keyboard auto-repeat implemented on a Windows PC?
I understand that low level keyboard hook does't receive auto-repeat count :/
Note that the low level keyboard hook (WH_KEYBOARD_LL) does not receive the repeat count.
But why?? o.O
The way I used to extract the auto-repeat count using windows messages:
int repeatCount = (lParam & KF_REPEAT);
But it doesn't work for some reason when I use the SetWindowsHookEx
hooking the WH_KEYBOARD_LL
.
I want to filter auto-repeat for the Space
key while using the global hook. Is there a way doing that? Possibly a creative way to determine if the key down press is auto-repeated(i.e held down)?
Sample code:
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
{
KBDLLHOOKSTRUCT kbd = *(KBDLLHOOKSTRUCT *)(lParam);
if (kbd.vkCode == VK_SPACE && !(lParam & KF_REPEAT))
{
// do something
}
}
I understand that low level keyboard hook does't receive auto-repeat count ... But why??
Because the auto-repeat counter simply does not exist at the low level. At that level, you are getting events from the keyboard itself. Key down, key up, that is it. The keyboard is not in control of the counter.
At a higher level, when the system is processing those low level events from the keyboard and generating key messages for distribution to apps, the system runs its own timer to manage the repeat counter and create the corresponding key messages whenever the counter is incremented.
I want to filter auto-repeat for the
Space
key while using the global hook. Is there a way doing that?
In a low level hook, you will have to run your own timer, just like the system does.
Otherwise, use a higher level message hook instead of a keyboard hook.