Exemplo n.º 1
0
        private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                return(HookCallbackInner(nCode, wParam, lParam));
            }
            catch
            { }

            return(InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam));
        }
Exemplo n.º 2
0
        private IntPtr HookCallbackInner(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                int vkCode = Marshal.ReadInt32(lParam);

                if (wParam == (IntPtr)InterceptKeys.WM_KEYDOWN || wParam == (IntPtr)InterceptKeys.WM_SYS_KEYDOWN)
                {
                    KeyDown?.Invoke(this, new RawKeyEventArgs(vkCode, false));
                }
                else if (wParam == (IntPtr)InterceptKeys.WM_KEYUP || wParam == (IntPtr)InterceptKeys.WM_SYS_KEYUP)
                {
                    KeyUp?.Invoke(this, new RawKeyEventArgs(vkCode, false));
                }
            }

            return(InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam));
        }