Note that there are some explanatory texts on larger screens.

plurals
  1. POSetWindowsHookEx global keyboard hook not catching all keypresses
    primarykey
    data
    text
    <p>I'm writing code that is part of an automation system. I wanted to add a keyboard hook to end the test prematurely, and I did this by using SetWindowHookEx.</p> <p>My code looks pretty much like this: <a href="http://support.microsoft.com/kb/318804" rel="nofollow noreferrer">http://support.microsoft.com/kb/318804</a></p> <p>Here's my SetWindowsHookEx call:</p> <pre><code>hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0); </code></pre> <p>Now, when I run my automation, keypresses from within the automation system (from SendKeys) trigger the keyboard hook method, but when I hit the keyboard manually it isn't triggered.</p> <p>I can share more code if that helps, but it's part of a much larger system. I'm pretty sure that either:</p> <ol> <li>My SetWindowsHookEx isn't correct, or <li>Something in the automation system is bypassing my keyboard hook (I don't really know how to tell though). </ol> <p>I've written a test application that uses the sample code from microsoft.com to determine that my approach has merit (i.e., it works), but I'm having trouble integrating it with the automation system.</p> <p>Any thoughts on how to determine where things are going wrong would be greatly appreciated.</p> <p>Edit: There are no other instances of SetWindowsHookEx in the automation harness. I'm not too clear the nuances of global keyboard hooks w.r.t. threads and the desktop. If I add a global keyboard hook, should it matter from where it was added?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload