public int ProcessMessage(Message message)
        {
            bool handled = false;

            if (_hookProcess != null)
            {
                if (message.Msg == _hookMessage)
                {
                    Keys key = (Keys)message.WParam.ToInt32();

                    long lParam = message.LParam.ToInt64();
                    Win32.KeyboardParams parameters = new Win32.KeyboardParams(((int)(lParam & 0xFFFFFFFF)));
                    bool keyDown = (parameters.transitionState == Win32.KeyboardParams.TransitionState.Down);

                    _keyState.KeyPress(keyDown, key, parameters.extendedKey);

                    if (KeyEvent != null)
                    {
                        KeyHookEventArgs e = new KeyHookEventArgs(_keyState);
                        KeyEvent(this, e);
                        handled |= e.Handled;
                    }
                }
                if (message.Msg == _hookMessageLowLevel)
                {
                    Keys key = (Keys)message.WParam.ToInt32();

                    long lParam = message.LParam.ToInt64();
                    Win32.KeyboardParams parameters = new Win32.KeyboardParams(((int)(lParam & 0xFFFFFFFF)));
                    bool keyDown = (parameters.transitionState == Win32.KeyboardParams.TransitionState.Down);

                    _keyStateLowLevel.KeyPress(keyDown, key, parameters.extendedKey);

                    if (KeyEventLowLevel != null)
                    {
                        KeyHookEventArgs e = new KeyHookEventArgs(_keyStateLowLevel);
                        KeyEventLowLevel(this, e);
                        handled |= e.Handled;
                    }
                }

                if (KeysDownCount() == 0)
                {
                    _allKeysUpEvent.Set();
                }
                else
                {
                    _allKeysUpEvent.Reset();
                }

                if (handled)
                {
                    return(-1);
                }
            }

            return(0);
        }
예제 #2
0
        void Current_KeyEventLowLevel(object sender, KeyHookEventArgs e)
        {
            if (e.KeyCombination.KeyDown == false)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                Current_KeyEventLowLevelDelegate function = new Current_KeyEventLowLevelDelegate(Current_KeyEventLowLevelThread);
                function.BeginInvoke(e.KeyCombination, asyncResult => { function.EndInvoke(asyncResult); }, null);
            }
            else
            {
                Current_KeyEventLowLevel(e.KeyCombination);
            }

            e.Handled = true;
        }