If I understand your problem correctly, you should ignore the "nested" key events
follow these steps:
LRESULT CALLBACK hook_proc( int code, WPARAM wParam, LPARAM lParam ) { KBDLLHOOKSTRUCT* kbd = (KBDLLHOOKSTRUCT*)lParam; // Ignore injected events if (code < 0 || (kbd->flags & 0x10)) { return CallNextHookEx(kbdhook, code, wParam, lParam); } ...
Update: Additionally you must eat characters and notify about some other routines.
for character click through windows messages.
Example:
... // Pseudocode if (kbd->vkCode is character) { if (WM_KEYDOWN == wParam) { PostMessage(mainwnd, WM_MY_KEYDOWN, kbd->vkCode, 0); return 1; // eat the char, ie 'a' } } return CallNextHookEx(kbdhook, code, wParam, lParam);
And in some other module you are processing WM_MY_KEYDOWN
ie, #define WM_MY_KEYDOWN (WM_USER + 1)
and call the appropriate procedure that will generate new key events.
source share