Hello,
I need to write code which detects whether keystrokes are injected by applications (with SendInput, keybd_event) or are genuinely coming from the keyboard.
I came across a possible solution: creating a WH_KEYBOARD_LL hook and checking the INJECTED flag.
So I've made this so far:
HHOOK g_hHook;
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{
KBDLLHOOKSTRUCT *kd = (KBDLLHOOKSTRUCT *)lParam;
cg.ei.Com_Printf( "LowLevelKeyboardProc: flags = %08X\n", kd->flags );
return CallNextHookEx( g_hHook, nCode, wParam, lParam );
}
void InitHooks( void ) {
g_hHook = SetWindowsHookExA( WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle( NULL ), 0 );
}
This code is placed inside a DLL and the DLL is loaded by an EXE, an OpenGL powered game engine.
It catches all keystrokes which are sent to windows, with the exception of my game window, and that is the problem. I need it to catch the keystrokes sent to the game window as well.
Could you please help me with this?
Kind regards
NT