Exemplo n.º 1
0
 public KeyboardListener()
 {
     //The last hook will be garbage collected if we assign it again
     if (_HookID == IntPtr.Zero)
     {
         _HookID = KeyInterceptor.Hook(HookCallback);
     }
 }
Exemplo n.º 2
0
        private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                return(InnerHookCallback(nCode, wParam, lParam));
            }
            catch (Exception)
            {
                //Ignore this
            }

            return(KeyInterceptor.CallNextHookEx(_HookID, nCode, wParam, lParam));
        }
Exemplo n.º 3
0
        private IntPtr InnerHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if (wParam == (IntPtr)KeyInterceptor.KeyDown)
                {
                    KeyDown(this, new RawKeyEventArgs(Marshal.ReadInt32(lParam), false));
                }
                else if (wParam == (IntPtr)KeyInterceptor.KeyUp)
                {
                    KeyUp(this, new RawKeyEventArgs(Marshal.ReadInt32(lParam), false));
                }
            }

            return(KeyInterceptor.CallNextHookEx(_HookID, nCode, wParam, lParam));
        }
Exemplo n.º 4
0
 public void Dispose()
 {
     KeyInterceptor.UnhookWindowsHookEx(_HookID);
 }