private IntPtr SetHook(KeyboardProcedure proc) { Process currentProcess = Process.GetCurrentProcess(); ProcessModule currentModule = currentProcess.MainModule; return(SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(currentModule.ModuleName), 0)); }
private void UnhookKeyboard() { if (keyboardHookId != IntPtr.Zero) { UnhookWindowsHookEx(keyboardHookId); keyboardHookId = IntPtr.Zero; CurrentKeyboardProcedure = null; } }
public void HookKeyboard() { CurrentKeyboardProcedure = HookCallback; using (Process currentProcess = Process.GetCurrentProcess()) { using (ProcessModule currentModule = currentProcess.MainModule) { Debug.Assert(keyboardHookId == IntPtr.Zero); keyboardHookId = SetWindowsHookEx(WH_KEYBOARD_LL, CurrentKeyboardProcedure, GetModuleHandle(currentModule.ModuleName), 0); } } }
private static extern IntPtr SetWindowsHookEx(int idHook, KeyboardProcedure lpfn, IntPtr hMod, uint dwThreadId);
public static IntPtr SetWindowsHookEx(int idHook, KeyboardProcedure lpfn, IntPtr hMod, uint dwThreadId) { return(SetWindowsHookExNative(idHook, lpfn, hMod, dwThreadId)); }
private IntPtr SetHook(KeyboardProcedure proc) { using (Process currentProcess = Process.GetCurrentProcess()) using (ProcessModule currentModule = currentProcess.MainModule) { return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(currentModule.ModuleName), 0); } }