Пример #1
0
        /// <summary>
        /// This is the call-back method that is called whenever a keyboard event is triggered.
        /// We use it to call our individual custom events.
        /// </summary>
        private IntPtr KeyboardHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (!Enabled)
            {
                return(Win32.CallNextHookEx(hookId, nCode, wParam, lParam));
            }

            if (nCode >= 0)
            {
                var lParamStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
                var e            = new KeyboardHookEventArgs(lParamStruct);
                switch ((KeyboardMessages)wParam)
                {
                case KeyboardMessages.WmSyskeydown:
                case KeyboardMessages.WmKeydown:
                    e.KeyboardEventName = KeyboardEventNames.KeyDown;
                    OnKeyboardKeyDown(e);
                    break;

                case KeyboardMessages.WmSyskeyup:
                case KeyboardMessages.WmKeyup:
                    e.KeyboardEventName = KeyboardEventNames.KeyUp;
                    OnKeyboardKeyUp(e);
                    break;
                }

                if (e.Handled)
                {
                    return((IntPtr)(-1));
                }
            }
            return(Win32.CallNextHookEx(hookId, nCode, wParam, lParam));
        }
Пример #2
0
 private void OnKeyboardKeyEvent(KeyboardHookEventArgs e)
 {
     if (KeyBoardKeyEvent != null)
     {
         KeyBoardKeyEvent(this, e);
     }
 }
Пример #3
0
 private void OnKeyboardKeyDown(KeyboardHookEventArgs e)
 {
     if (KeyBoardKeyDown != null)
     {
         KeyBoardKeyDown(this, e);
     }
     OnKeyboardKeyEvent(e);
 }
 private void OnKeyboardKeyUp(KeyboardHookEventArgs e)
 {
     if (KeyBoardKeyUp != null)
         KeyBoardKeyUp(this, e);
     OnKeyboardKeyEvent(e);
 }
        /// <summary>
        /// This is the call-back method that is called whenever a keyboard event is triggered.
        /// We use it to call our individual custom events.
        /// </summary>
        private IntPtr KeyboardHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (!Enabled) return Win32.CallNextHookEx(hookId, nCode, wParam, lParam);

            if (nCode >= 0)
            {
                var lParamStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
                var e = new KeyboardHookEventArgs(lParamStruct);
                switch ((KeyboardMessages)wParam)
                {
                    case KeyboardMessages.WmSyskeydown:
                    case KeyboardMessages.WmKeydown:
                        e.KeyboardEventName = KeyboardEventNames.KeyDown;
                        OnKeyboardKeyDown(e);
                        break;

                    case KeyboardMessages.WmSyskeyup:
                    case KeyboardMessages.WmKeyup:
                        e.KeyboardEventName = KeyboardEventNames.KeyUp;
                        OnKeyboardKeyUp(e);
                        break;
                }

                if (e.Handled) { return (IntPtr)(-1); }
            }
            return Win32.CallNextHookEx(hookId, nCode, wParam, lParam);
        }