Jump to content
  • Advertisement
Sign in to follow this  

SetWindowsHookExA + WH_KEYBOARD_LL trouble, callback not called

This topic is 2768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am experiencing trouble with a SetWindowsHookExA hook, specifically WM_KEYBOARD_LL.
I need to detect whether the keystrokes sent to a game window are injected or real.

But it turns out that the hook's callback doesn't even get called for the keystrokes sent to the game window, it is called for every other window.

/* ============== ! DLL CODE ! ============== */

HHOOK g_hHook;

LRESULT CALLBACK AC_LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )

Com_Printf( "CALLBACK! %03i ( %08X )\n", kd->scanCode, kd->flags );

return CallNextHookEx( g_hHook, nCode, wParam, lParam );

void AC_SetKeyboardHook( void ) {
if( !g_hHook ) {
g_hHook = SetWindowsHookExA( WH_KEYBOARD_LL, AC_LowLevelKeyboardProc, GetModuleHandle( NULL ), 0 );

void AC_DisableKeyboardHook( void ) {
if( g_hHook ) {
UnhookWindowsHookEx( g_hHook );

This code is put in DLL which is loaded by the main game executable (game is powered by OpenGL and DirectInput (mouse only)).

So, the callback function is never called when I press keys in the game window, it is called only for the other windows.

Surprisingly, if I hook from another EXE+DLL, it catches all keys, including the ones sent to the game. But I need to get it to work for the DLL game loads...

Kind regards :)

Share this post

Link to post
Share on other sites
or just NULL

GetModuleHandle(NULL) is wrong as it returns the hModule of the EXE
(which doesn't contain the HookProc)

and error checking is your friend in situations like this

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!