Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I took a look at the only constructor of the <code>globalKeyboardHook</code> and looks like it is designed only for global hook. You can add another overload to hook into the current running module only like this:</p> <pre><code>class globalKeyboardHook { [DllImport("kernel32")] private static extern int GetCurrentThreadId(); [DllImport("user32")] private static extern IntPtr SetWindowsHookEx(int hookType, KeyBoardProc proc, IntPtr moduleHandle, int threadId); [DllImport("user32")] private static extern int CallNextHookEx(IntPtr hHook, int nCode, IntPtr wParam, IntPtr lParam); public globalKeyboardHook(bool currentModuleOnly){ if(currentModuleOnly){ proc = KeyBoardCallback; //WH_KEYBOARD = 0x2 hhook = SetWindowsHookEx(2, proc, IntPtr.Zero, GetCurrentThreadId()); } else hook(); } public delegate int KeyBoardProc(int nCode, IntPtr wParam, IntPtr lParam); public int KeyBoardCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode &gt;= 0) { Keys key = (Keys)wParam; var lp = lParam.ToInt64(); //your own handling with the key if ((lp &gt;&gt; 31) == 0)//Key down { //your own code ... } else { //Key up //your own code ... } } return CallNextHookEx(hHook, nCode, wParam, lParam); } KeyBoardProc proc; //other code ... } //then use the new overload constructor instead of the parameterless constructor: globalHook = new globalKeyboardHook(true); </code></pre> <p><strong>NOTE</strong>: You can implement your own <code>KeyDown</code> and <code>KeyUp</code> event based on what I posted above (the comment <code>your own code ...</code>). After some searching I understand that the <code>WH_KEYBOARD_LL</code> supports <strong>global hook</strong> only while the <code>WH_KEYBOARD</code> is for <code>thread hook</code> only. That should be what you want instead of the <code>WH_KEYBOARD_LL</code>.</p> <p>BTW, I doubt that the <code>IMessageFilter</code> which can be registered/added by your application can be used in this case. It also supports a <code>PreFilterMessage</code> method helping you to intercept any key and mouse messages at the <code>application-level</code>. You should try searching on that, it's easy to follow.</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.
    1. This table or related slice is empty.
    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