public static IntPtr SetHook(WinAPI.LowLevelKeyboardProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(WinAPI.SetWindowsHookEx(WH_KEYBOARD_LL, proc, WinAPI.GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #2
0
        /// <summary>
        /// Sets up the global low level keyboard hook
        /// </summary>
        public HookManager()
        {
            keyboardDelegate = keyboardHookProcedure;

            hhook = WinAPI.SetWindowsHookEx(
                WinAPI.WH_KEYBOARD_LL,
                keyboardDelegate,
                IntPtr.Zero,
                0);

            if (hhook == IntPtr.Zero)
            {
                int errorCode =
                    System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                throw new System.ComponentModel.Win32Exception(errorCode);
            }
        }
 private KeyInterceptor()
 {
     mCallback = HookCallback;
     mHookID   = SetHook(mCallback);
     AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
 }