Exemplo n.º 1
0
        private IntPtr HookCallbackInner(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if (wParam == (IntPtr)InterceptKeys.WM_KEYDOWN)
                {
                    int vkCode = Marshal.ReadInt32(lParam);

                    if (KeyDown != null)
                    {
                        KeyDown(this, new RawKeyEventArgs(vkCode, false));
                    }
                }
                else if (wParam == (IntPtr)InterceptKeys.WM_KEYUP)
                {
                    int vkCode = Marshal.ReadInt32(lParam);

                    if (KeyUp != null)
                    {
                        KeyUp(this, new RawKeyEventArgs(vkCode, false));
                    }
                }
            }
            return(InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam));
        }
Exemplo n.º 2
0
 private IntPtr HookCallback(
     int nCode, IntPtr wParam, IntPtr lParam)
 {
     try
     {
         return(HookCallbackInner(nCode, wParam, lParam));
     }
     catch
     {
         Console.WriteLine("There was some error somewhere...");
     }
     return(InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam));
 }
Exemplo n.º 3
0
 public void Dispose()
 {
     InterceptKeys.UnhookWindowsHookEx(hookId);
 }
Exemplo n.º 4
0
 public KeyboardListener()
 {
     hookId = InterceptKeys.SetHook((InterceptKeys.LowLevelKeyboardProc)HookCallback);
 }