/// <summary>
        /// Handler for mouse click event
        /// </summary>
        /// <typeparam name="TMouseEvent">Generic parameter, since keyDown and keyUp events have different type for eventArgs</typeparam>
        private void OnMouseOnButtonEvent <TMouseEvent>(EventSourceEventArgs <TMouseEvent> e, MouseEventType eventType) where TMouseEvent : ButtonEvent
        {
            if (!_hotkeyConditionService.ShouldHandleHotkeyEvent(e.Data))
            {
                return;
            }

            InputResult  inputResult;
            UserInputKey mappedKey = _keyMapper.MapToUserInputKey(e.Data.Button);

            if (eventType == MouseEventType.KeyDown)
            {
                inputResult = _keyHandler.OnKeyDown(mappedKey, ModifierKeys.None);
            }
            else
            {
                inputResult = _keyHandler.OnKeyUp(mappedKey);
            }


            if (inputResult.HasFlag(InputResult.HideFromOtherApplications))
            {
                e.Next_Hook_Enabled = false;
            }
        }
        /// <summary>
        /// Handler for keyboard key press event
        /// </summary>
        private void OnKeyEvent(object sender, EventSourceEventArgs <KeyboardEvent> keyboardEventArgs)
        {
            if (keyboardEventArgs.Data == null)
            {
                return;
            }

            if (!_hotkeyConditionService.ShouldHandleHotkeyEvent(keyboardEventArgs.Data))
            {
                return;
            }


            InputResult?inputResult = null;

            if (keyboardEventArgs.Data.KeyDown != null)
            {
                UserInputKey mappedKey    = _keyMapper.MapToUserInputKey(keyboardEventArgs.Data.KeyDown.Key);
                ModifierKeys modifierKeys = GetModifierKeys();
                inputResult = _keyHandler.OnKeyDown(mappedKey, modifierKeys);
            }
            else if (keyboardEventArgs.Data.KeyUp != null)
            {
                UserInputKey mappedKey = _keyMapper.MapToUserInputKey(keyboardEventArgs.Data.KeyUp.Key);
                inputResult = _keyHandler.OnKeyUp(mappedKey);
            }

            if (inputResult.HasValue && inputResult.Value.HasFlag(InputResult.HideFromOtherApplications))
            {
                keyboardEventArgs.Next_Hook_Enabled = false;
            }
        }
示例#3
0
        private void Log <T>(EventSourceEventArgs <T> e, string Notes = "") where T : InputEvent
        {
            var NewContent = "";

            NewContent += $"{e.Timestamp}: {Notes}\r\n";
            foreach (var item in e.Data.Events)
            {
                NewContent += $"  {item}\r\n";
            }
            NewContent += "\r\n";

            textBoxLog.Text = NewContent + textBoxLog.Text;
        }
        /// <summary>
        /// Handler for mouse scroll event. Does not affect clicks
        /// </summary>
        private void OnMouseScroll(object sender, EventSourceEventArgs <ButtonScroll> mouseEventArgs)
        {
            if (!_hotkeyConditionService.ShouldHandleHotkeyEvent(mouseEventArgs.Data))
            {
                return;
            }

            UserInputKey mappedKey   = _keyMapper.MapToUserInputKey(mouseEventArgs.Data.Offset);
            InputResult? inputResult = _keyHandler.OnKeyDown(mappedKey, ModifierKeys.None);

            if (inputResult.Value.HasFlag(InputResult.HideFromOtherApplications))
            {
                mouseEventArgs.Next_Hook_Enabled = false;
            }
        }
 private static void H_MouseEvent(object sender, EventSourceEventArgs <MouseEvent> e)
 {
     //if (e.Data.ButtonDown is not null)
     //{
     //    Trace.WriteLine("正确的");
     //}
     //if (e.Data.ButtonClick is not null)
     //{
     //    Trace.WriteLine("正确的");
     //}
     //if (e.Data.ButtonUp is not null)
     //{
     //    Trace.WriteLine("正确的");
     //}
 }
示例#6
0
        private void Mouse_MouseEvent(object sender, EventSourceEventArgs <MouseEvent> e)
        {
            var Notes = "";

            if (checkBoxSuppressMouse.Checked && e.Data.ButtonClick != default && e.Data.ButtonClick.Button == WindowsInput.Events.ButtonCode.Right)
            {
                e.Next_Event_Enabled = true;

                Notes = "SUPPRESSED!!!";
            }

            if (checkBoxSupressMouseWheel.Checked && e.Data.ButtonScroll != default)
            {
                e.Next_Event_Enabled = true;
                Notes = "SUPPRESSED!!!";
            }
            Log(e, Notes);
        }
示例#7
0
        /// <summary>
        ///     Creates <see cref="MouseInput" /> from relevant mouse data.
        /// </summary>
        /// <param name="wParam">First Windows Message parameter.</param>
        /// <param name="mouseInfo">A MouseStruct containing information from which to construct MouseEventExtArgs.</param>
        /// <returns>A new MouseEventExtArgs object.</returns>
        private static EventSourceEventArgs <MouseInput> ToMouseEventArgs(GlobalMouseEventSourceCallbackData data)
        {
            var   button     = ButtonCode.None;
            short mouseDelta = 0;

            var isMouseButtonDown = false;
            var isMouseButtonUp   = false;

            switch (data.Message)
            {
            case WindowMessage.WM_LBUTTONDOWN:
                isMouseButtonDown = true;
                button            = ButtonCode.Left;
                break;

            case WindowMessage.WM_LBUTTONUP:
                isMouseButtonUp = true;
                button          = ButtonCode.Left;
                break;

            case WindowMessage.WM_LBUTTONDBLCLK:
                isMouseButtonDown = true;
                button            = ButtonCode.Left;
                break;

            case WindowMessage.WM_RBUTTONDOWN:
                isMouseButtonDown = true;
                button            = ButtonCode.Right;
                break;

            case WindowMessage.WM_RBUTTONUP:
                isMouseButtonUp = true;
                button          = ButtonCode.Right;
                break;

            case WindowMessage.WM_RBUTTONDBLCLK:
                isMouseButtonDown = true;
                button            = ButtonCode.Right;
                break;

            case WindowMessage.WM_MBUTTONDOWN:
                isMouseButtonDown = true;
                button            = ButtonCode.Middle;
                break;

            case WindowMessage.WM_MBUTTONUP:
                isMouseButtonUp = true;
                button          = ButtonCode.Middle;
                break;

            case WindowMessage.WM_MBUTTONDBLCLK:
                isMouseButtonDown = true;
                button            = ButtonCode.Middle;
                break;

            case WindowMessage.WM_MOUSEWHEEL_V:
                button     = ButtonCode.VScroll;
                mouseDelta = data.Data.MouseDataValue;
                break;

            case WindowMessage.WM_XBUTTONDOWN:
                button = data.Data.MouseData == MouseData.XButton1_Click
                        ? ButtonCode.XButton1
                        : ButtonCode.XButton2;
                isMouseButtonDown = true;
                break;

            case WindowMessage.WM_XBUTTONUP:
                button = data.Data.MouseData == MouseData.XButton1_Click
                        ? ButtonCode.XButton1
                        : ButtonCode.XButton2;
                isMouseButtonUp = true;
                break;

            case WindowMessage.WM_XBUTTONDBLCLK:
                isMouseButtonDown = true;
                button            = data.Data.MouseData == MouseData.XButton1_Click
                        ? ButtonCode.XButton1
                        : ButtonCode.XButton2;
                break;

            case WindowMessage.WM_MOUSEWHEEL_H:
                button     = ButtonCode.HScroll;
                mouseDelta = data.Data.MouseDataValue;
                break;
            }

            var Status = ButtonStatusValue.Compute(isMouseButtonDown, isMouseButtonUp, mouseDelta);

            var ret = EventSourceEventArgs.Create(data.Data.Timestamp, new MouseInput(button, data.Data.Point, mouseDelta, Status), data);

            return(ret);
        }
示例#8
0
 private static void Item_KeyEvent(object sender, EventSourceEventArgs<KeyboardEvent> e) {
     if (e.Data.KeyDown?.Key == WindowsInput.Events.KeyCode.W || e.Data.KeyUp?.Key == WindowsInput.Events.KeyCode.W) {
         //Tell the OS to ignore this key
         e.Next_Hook_Enabled = false;
     }
 }
 private void H_ButtonClickHold(object sender, EventSourceEventArgs <ButtonClickHold> e)
 {
     Trace.WriteLine("Hold");
 }
 private void H_ButtonUp(object sender, EventSourceEventArgs <ButtonUp> e)
 {
     Trace.WriteLine("up");
 }
 private void H_ButtonScroll(object sender, EventSourceEventArgs <ButtonScroll> e)
 {
     Trace.WriteLine("Button Scroll");
 }
 private void H_ButtonDoubleClick(object sender, EventSourceEventArgs <ButtonDoubleClick> e)
 {
     Trace.WriteLine("Double");
 }
示例#13
0
 private void Keyboard_KeyEvent(object sender, EventSourceEventArgs <KeyboardEvent> e)
 {
     Log(e);
 }