Ejemplo n.º 1
0
        private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Key              vkCode = Key.None;
            IntPtr           retVal = IntPtr.Zero;
            KeyboardHookArgs args   = null;

            if (nCode >= 0)
            {
                vkCode = (Key)Marshal.ReadInt32(lParam);
                args   = new KeyboardHookArgs(vkCode, false);

                if ((IntPtr)WM_KEYUP == wParam)
                {
                    KeyUpEvent(args);
                }
                else if ((IntPtr)WM_KEYDOWN == wParam)
                {
                    KeyDownEvent(args);
                }
                else if ((IntPtr)WM_SYSKEYUP == wParam)
                {
                    Console.WriteLine($"SystemKey: {args.Key.ToString()}");
                }
                else
                {
                    Console.WriteLine($"UnhandledKey: {args.Key.ToString()}");
                }
            }

            if (true == args?.Handled)
            {
                retVal = (IntPtr)1;
            }
            else
            {
                retVal = CallNextHookEx(_hookID, nCode, wParam, lParam);
            }
            return(retVal);
        }
Ejemplo n.º 2
0
 private void KeyPressedEvent(KeyboardHookArgs args)
 {
     OnKeyPressed?.Invoke(this, args);
 }
Ejemplo n.º 3
0
 private void KeyDownEvent(KeyboardHookArgs args)
 {
     OnKeyDown?.Invoke(this, args);
 }