Ejemplo n.º 1
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (kbHookHandle != IntPtr.Zero)
         {
             GlobalHooksHelper.UnhookWindowsHookEx(kbHookHandle);
         }
         disposed = true;
     }
 }
Ejemplo n.º 2
0
        private IntPtr KeyboardHookDelegate(Int32 nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN))
            {
                int vkCode = Marshal.ReadInt32(lParam);
                if (null != KeyPressEvent)
                {
                    KeyPressEvent(this, new KeyPressedArgs(KeyInterop.KeyFromVirtualKey(vkCode)));
                }
            }

            return(GlobalHooksHelper.CallNextHookEx(kbHookHandle, nCode, wParam, lParam));
        }
Ejemplo n.º 3
0
 public KeyboardHook()
 {
     kbHookDelegate = KeyboardHookDelegate;
     kbHookHandle   = GlobalHooksHelper.SetWindowsHookEx(WH_KEYBOARD_LL, kbHookDelegate, IntPtr.Zero, 0);
 }