private static IntPtr SetHook(NativeWin32.LowLevelKeyboardProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(NativeWin32.SetWindowsHookEx(WH_KEYBOARD_LL, proc,
                                                 NativeWin32.GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #2
0
 private void hook(IntPtr hInstance)
 {
     callbackDelegate = new keyboardHookProc(hookProc);
     GC.KeepAlive(callbackDelegate);
     HHook = NativeWin32.SetWindowsHookEx(WH_KEYBOARD_LL, callbackDelegate, hInstance, 0);
     if (HHook == IntPtr.Zero)
     {
         throw new Win32Exception(Marshal.GetLastWin32Error());
     }
 }