WH_KEYBOARD_LL hook not called

后端 未结 3 890
心在旅途
心在旅途 2021-01-23 12:35

I\'m having some problems with a WH_KEYBOARD_LL hook :

The reason why I\'m using a global LL hook is not important I just need it for my app (I tried other

相关标签:
3条回答
  • 2021-01-23 13:15

    The hook callback is made on the same thread that called SetWindowsHookEx(). That bit of magic requires that thread to pump a message loop. Which is the rub, your timer callback method is called from a threadpool thread. It doesn't pump, it's not even around long enough to ever be able to get the hook callback.

    Invoke to your UI thread or use a synchronous timer. Or consider just temporarily disabling whatever you do in the hook callback instead of completely disabling or replacing the hook, that certainly makes most sense.

    0 讨论(0)
  • 2021-01-23 13:19

    For what it's worth, I use GetModuleHandle(0) for SetWindowsHookEx in my code. I have no idea if this is your problem -- my code is single-threaded.

    0 讨论(0)
  • 2021-01-23 13:25

    You could check the foreground window in your hook function instead, and get rid of the timer thread altogether. That's what I do in TouchCursor. You can look at my code on SourceForge -- Line 553 for the hook function.

    0 讨论(0)
提交回复
热议问题