示例#1
0
 private void OnMouseEvent(object sender, GlobalMouseHookEventArgs e)
 {
     if (m_ControlMode == ControlMode.Remapper)
     {
         m_Remapper.OnMouseEvent(sender, e);
     }
     else if (m_ControlMode == ControlMode.StatusChecker)
     {
         m_StatusChecker.OnMouseEvent(sender, e);
     }
 }
示例#2
0
            /// <summary>
            /// This method will call the OnButtonUp event exposed from the library and pass on information about the button that was let go and the location of the mouse pointer.
            /// </summary>
            /// <param name="e">Argument passed by the MouseEvent under the Internal GlobalMouseHook.</param>
            /// <returns>Returns true if the event was handled and false if not.</returns>
            bool ButtonUp(GlobalMouseHookEventArgs e)
            {
                GHMouseButtons mouseButton = MouseMessageToGHMouseButton(e.MouseMessages, e.MouseData.mouseData);

                currentMouseButtonsPressed.Add(mouseButton); //Add mouse button to the list of currently being pressed mouse buttons.

                MousePosition mousePosition = new MousePosition(e.MouseData.pt.x, e.MouseData.pt.y);

                GlobalMouseEventArgs globalMouseEventArgs = new GlobalMouseEventArgs(mouseButton, mousePosition);

                return(CallEvent(OnButtonUp, globalMouseEventArgs));
            }
示例#3
0
            bool MouseWheelEvent(GlobalMouseHookEventArgs e)
            {
                MousePosition mousePosition = new MousePosition(e.MouseData.pt.x, e.MouseData.pt.y);

                /* Compared to the other events, we need to find the rotation of the scroll wheel (wheel delta). Unfortunately, the low level mouse event doesn't pass it as a human readable value.
                 * Instead, it is passed on as a high order word of the e.mouseData.mouseData value. We have to retrieve that High Order Word by using a helper function called GetSignedHWord.*/
                WheelRotation wheelRotation = (WheelRotation)(Helper.GetSignedHWORD(e.MouseData.mouseData)); //The Wheel Delta will always be either 120 for forwards movement and -120 for backwards movement which is already declared on the WheelRotation enum. All we have to do is cast the Wheel Delta to WheelRotation.


                GlobalMouseEventArgs globalMouseEventArgs = new GlobalMouseEventArgs(GHMouseButtons.None, mousePosition, wheelRotation);

                return(CallEvent(OnMouseWheelScroll, globalMouseEventArgs));
            }
示例#4
0
            /// <summary>
            /// This method will call the OnButtonDown event exposed from the library and pass on information about the button that was pressed and the location of the mouse pointer.
            /// </summary>
            /// <param name="e">Argument passed by the MouseEvent under the Internal GlobalMouseHook.</param>
            /// <returns>Returns true if the event was handled and false if not.</returns>
            bool ButtonDown(GlobalMouseHookEventArgs e)
            {
                GHMouseButtons mouseButton = MouseMessageToGHMouseButton(e.MouseMessages, e.MouseData.mouseData); //We convert the ugly looking MouseMessages to an enumartion of the GHMouseButtons.

                currentMouseButtonsPressed.Remove(mouseButton);                                                   //Remove the mouse button from the list of buttons currently being pressed.

                MousePosition mousePosition = new MousePosition(e.MouseData.pt.x, e.MouseData.pt.y);              //Store the x and y coordinates of the mouse pointer on the screen.

                GlobalMouseEventArgs globalMouseEventArgs = new GlobalMouseEventArgs(mouseButton, mousePosition); //Now, we store the values of the mouseButton and the mousePosition into one class which will be the argument for the OnButtonDown event.

                return(CallEvent(OnButtonDown, globalMouseEventArgs));                                            //Let's now call the CallEvent method which handles the necessary "set up" needed before calling the OnButtonDown event for us. We also pass on the globalMouseEventArgs as the argument of the event.
                                                                                                                  //It also returns a boolean value which tells us if the event was handled. We have to pass that value back to the _globalMouseHook_MouseEvent method.
            }
示例#5
0
        private unsafe IntPtr LowLevelMouseAction(int nCode, IntPtr wParam, IntPtr lParam)
        {
            var state = (MouseState)(wParam.ToInt32() - 1); // fix for MouseMove 0x200 mask

            if ((MouseState.All & state) == state)
            {
                var p = Unsafe.Read <LowLevelMouseInputEvent>(lParam.ToPointer());

                var args = new GlobalMouseHookEventArgs(p, state);
                MousePressed?.Invoke(this, args);

                if (args.Handled)
                {
                    return((IntPtr)1);
                }
            }

            return(User32.CallNextHookEx(MouseHookHandle, nCode, wParam, lParam));
        }
示例#6
0
            private IntPtr LowLevelMouseEvent(int nCode, IntPtr wParam, IntPtr lParam)
            {
                bool fEatMouseEvent = false;

                var wparamTyped = wParam.ToInt32();

                if (Enum.IsDefined(typeof(MouseMessages), wparamTyped))
                {
                    object         o = Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                    MSLLHOOKSTRUCT p = (MSLLHOOKSTRUCT)o;

                    var eventArguments = new GlobalMouseHookEventArgs((MouseMessages)wparamTyped, p);

                    EventHandler <GlobalMouseHookEventArgs> handler = MouseEvent;
                    handler?.Invoke(this, eventArguments);

                    fEatMouseEvent = eventArguments.Handled;
                }

                return(fEatMouseEvent ? (IntPtr)(-1) : DLLImports.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
            }
示例#7
0
 //This method will be called when a Mouse Event happens.
 private void _globalMouseHook_MouseEvent(object sender, GlobalMouseHookEventArgs e)
 {
     if (e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_LBUTTONDOWN || e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_MBUTTONDOWN ||
         e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_RBUTTONDOWN || e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_XBUTTONDOWN)
     {
         e.Handled = ButtonDown(e); //If the left, middle, right or the X buttons were pressed, we call the ButtonDown method which handles the calling of the OnButtonDown event.
                                    // The ButtonDown method also returns a bool value. If it is set to true, succeeding events handling a ButtonDown will not be called.
     }
     else if (e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_LBUTTONUP || e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_MBUTTONUP ||
              e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_RBUTTONUP || e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_XBUTTONUP)
     {
         e.Handled = ButtonUp(e); //If the left, middle, right or the X buttons were released, we call the ButtonUp method which handles the calling of the OnButtonUp event.
     }
     else if (e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_MOUSEMOVE)
     {
         e.Handled = MouseMove(e.MouseData.pt); //If the mouse pointers on the screen, we call the MouseMove method which handles the calling of the OnMouseMove event.
     }
     else if (e.MouseMessages == InternalGlobalMouseHook.MouseMessages.WM_MOUSEWHEEL)
     {
         e.Handled = MouseWheelEvent(e); //If the mouse wheel was rotated, we call the MouseWheelEvent method which handles the OnMouseWheelScroll event.
     }
 }
示例#8
0
        public void OnMouseEvent(object sender, GlobalMouseHookEventArgs e)
        {
            bool focusedWindow = CheckFocusedWindow();

            // Focused
            if (focusedWindow)
            {
                if (EnableMouseInput)
                {
                    // Hide cursor
                    if (!DebugCursor && IsCursorShowing)
                    {
                        ShowCursorAndToolbar(false);
                    }
                }
            }
            // Not focused
            else
            {
                // Show cursor
                if (!DebugCursor && !IsCursorShowing)
                {
                    ShowCursorAndToolbar(true);
                }

                // Ignore the rest if not focused
                return;
            }

            // Ignore if disabled
            if (!EnableMouseInput)
            {
                return;
            }

            #region Mouse clicks
            // Left mouse
            if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonDown)
            {
                LeftMouseDown = true;
                e.Handled     = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonUp)
            {
                LeftMouseDown = false;
                e.Handled     = focusedWindow;
            }
            // Right mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonDown)
            {
                RightMouseDown = true;
                e.Handled      = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonUp)
            {
                RightMouseDown = false;
                e.Handled      = focusedWindow;
            }
            // Middle mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonDown)
            {
                MiddleMouseDown = true;
                e.Handled       = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonUp)
            {
                MiddleMouseDown = false;
                e.Handled       = focusedWindow;
            }
            #endregion
            #region Mouse move
            else if (e.MouseState == GlobalMouseHook.MouseState.Move)
            {
                var rawX = e.MouseData.Point.X;
                var rawY = e.MouseData.Point.Y;

                var rawXOld = rawX;
                var rawYOld = rawY;
                //Console.Write(rawX);

                #region Store mouse stroke
                var newStroke = new MouseStroke()
                {
                    Timestamp = DateTime.Now,
                    RawData   = e,
                    DidMoved  = true,
                    X         = rawX + CursorOverflowX,
                    Y         = rawY + CursorOverflowY
                };

                if (CurrentMouseStroke != null)
                {
                    double deltaTime = (newStroke.Timestamp - CurrentMouseStroke.Timestamp).TotalSeconds;

                    if (deltaTime != 0) // moving too fast causes NaN
                    {
                        newStroke.VelocityX = (newStroke.X - CurrentMouseStroke.X) / deltaTime;
                        newStroke.VelocityY = (newStroke.Y - CurrentMouseStroke.Y) / deltaTime;
                        double newX = newStroke.VelocityX;
                        double newY = newStroke.VelocityY;

                        // increase lower values to high, because there are problems with PS4's deadzone (center + 64 to slowly moving mouse, center + 63 to not moving mouse)

                        Debug.WriteLine(newX);
                        if ((newX > -50 && newX < 0) || (newX > 0 && newX < 50))
                        {
                            newX = newX * (MouseDecayRate * 80);
                        }
                        else if ((newX > -100 && newX < 0) || (newX > 0 && newX < 100))
                        {
                            newX = newX * (MouseDecayRate * 70);
                        }
                        else if ((newX > -150 && newX < 0) || (newX > 0 && newX < 150))
                        {
                            newX = newX * (MouseDecayRate * 30);
                        }
                        else if ((newX > -200 && newX < 0) || (newX > 0 && newX < 200))
                        {
                            newX = newX * (MouseDecayRate * 10);
                        }

                        if ((newY > -50 && newY < 0) || (newY > 0 && newY < 50))
                        {
                            newY = newY * (MouseDecayRate * 80);
                        }
                        else if ((newY > -100 && newY < 0) || (newY > 0 && newY < 100))
                        {
                            newY = newY * (MouseDecayRate * 70);
                        }
                        else if ((newY > -150 && newY < 0) || (newY > 0 && newY < 150))
                        {
                            newY = newY * (MouseDecayRate * 30);
                        }
                        else if ((newY > -200 && newY < 0) || (newY > 0 && newY < 200))
                        {
                            newY = newY * (MouseDecayRate * 10);
                        }

                        if (MouseInvertXAxis == true)
                        {
                            newX = -newX;
                        }
                        if (MouseInvertYAxis == true)
                        {
                            newY = -newY;
                        }
                        CurrentX = CurrentX + ((newX * MouseSensitivity) / 10000);
                        CurrentY = CurrentY + ((newY * MouseSensitivity) / 10000);
                        Counter  = MouseMakeupSpeed;
                    }
                }

                CurrentMouseStroke = newStroke;
                #endregion

                #region Adjust cursor position;
                var didSetPosition = false;
                var screen         = Screen.FromHandle(RemotePlayProcess.MainWindowHandle);
                var workingArea    = screen.WorkingArea;
                var tmpX           = rawX - workingArea.X;
                var tmpY           = rawY - workingArea.Y;

                if (tmpX >= workingArea.Width)
                {
                    CursorOverflowX += workingArea.Width;
                    tmpX             = 0;
                    didSetPosition   = true;
                }
                else if (tmpX <= 0)
                {
                    CursorOverflowX -= workingArea.Width;
                    tmpX             = workingArea.Width;
                    didSetPosition   = true;
                }

                if (tmpY >= workingArea.Height)
                {
                    CursorOverflowY += workingArea.Height;
                    tmpY             = 0;
                    didSetPosition   = true;
                }
                else if (tmpY <= 0)
                {
                    CursorOverflowY -= workingArea.Height;
                    tmpY             = workingArea.Height;
                    didSetPosition   = true;
                }

                // Block cursor
                if (didSetPosition)
                {
                    RemapperUtility.SetCursorPosition(tmpX, tmpY);
                    e.Handled = true;
                }
                #endregion
                #endregion
            }
        }
示例#9
0
 public void OnMouseEvent(object sender, GlobalMouseHookEventArgs e)
 {
     UpdateStatus(MouseStatus);
 }
示例#10
0
        public void OnMouseEvent(object sender, GlobalMouseHookEventArgs e)
        {
            bool focusedWindow = CheckFocusedWindow();

            // Focused
            if (focusedWindow)
            {
                if (EnableMouseInput)
                {
                    // Hide cursor
                    if (!DebugCursor && IsCursorShowing)
                    {
                        ShowCursorAndToolbar(false);
                    }
                }
            }
            // Not focused
            else
            {
                // Show cursor
                if (!DebugCursor && !IsCursorShowing)
                {
                    ShowCursorAndToolbar(true);
                }

                // Ignore the rest if not focused
                return;
            }

            // Ignore if disabled
            if (!EnableMouseInput)
            {
                return;
            }

            // Left mouse
            if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonDown)
            {
                LeftMouseDown = true;
                e.Handled     = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonUp)
            {
                LeftMouseDown = false;
                e.Handled     = focusedWindow;
            }
            // Right mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonDown)
            {
                RightMouseDown = true;
                e.Handled      = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonUp)
            {
                RightMouseDown = false;
                e.Handled      = focusedWindow;
            }
            // Middle mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonDown)
            {
                MiddleMouseDown = true;
                e.Handled       = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonUp)
            {
                MiddleMouseDown = false;
                e.Handled       = focusedWindow;
            }
            // Mouse move
            else if (e.MouseState == GlobalMouseHook.MouseState.Move)
            {
                var rawX = e.MouseData.Point.X;
                var rawY = e.MouseData.Point.Y;

                // Ignore if at center
                if (rawX == MOUSE_CENTER_X && rawY == MOUSE_CENTER_Y)
                {
                    return;
                }

                #region Store mouse stroke
                var newStroke = new MouseStroke()
                {
                    Timestamp = DateTime.Now,
                    RawData   = e,
                    DidMoved  = true,
                    X         = rawX + CursorOverflowX,
                    Y         = rawY + CursorOverflowY
                };

                if (CurrentMouseStroke != null)
                {
                    double deltaTime = (newStroke.Timestamp - CurrentMouseStroke.Timestamp).TotalSeconds;
                    newStroke.VelocityX = (newStroke.X - CurrentMouseStroke.X) / deltaTime;
                    newStroke.VelocityY = (newStroke.Y - CurrentMouseStroke.Y) / deltaTime;
                }

                CurrentMouseStroke = newStroke;
                #endregion

                #region Adjust cursor position
                var tmpX           = rawX;
                var tmpY           = rawY;
                var didSetPosition = false;
                var workingArea    = Screen.PrimaryScreen.WorkingArea;

                if (tmpX >= workingArea.Width)
                {
                    CursorOverflowX += workingArea.Width;
                    tmpX             = 0;
                    didSetPosition   = true;
                }
                else if (tmpX <= 0)
                {
                    CursorOverflowX -= workingArea.Width;
                    tmpX             = workingArea.Width;
                    didSetPosition   = true;
                }

                if (tmpY >= workingArea.Height)
                {
                    CursorOverflowY += workingArea.Height;
                    tmpY             = 0;
                    didSetPosition   = true;
                }
                else if (tmpY <= 0)
                {
                    CursorOverflowY -= workingArea.Height;
                    tmpY             = workingArea.Height;
                    didSetPosition   = true;
                }

                // Block cursor
                if (didSetPosition)
                {
                    //RemapperUtility.SetCursorPosition(tmpX, tmpY);
                    e.Handled = true;
                }
                #endregion
            }
        }
示例#11
0
        public void OnMouseEvent(object sender, GlobalMouseHookEventArgs e)
        {
            bool focusedWindow = CheckFocusedWindow();

            // When not focused, we don't do anything.
            if (!focusedWindow)
            {
                return;
            }

            // Ignore if disabled
            if (!EnableMouseInput)
            {
                return;
            }

            #region Mouse clicks
            // Left mouse
            if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonDown)
            {
                LeftMouseDown = true;
                e.Handled     = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonUp)
            {
                LeftMouseDown = false;
                e.Handled     = focusedWindow;
            }
            // Right mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonDown)
            {
                RightMouseDown = true;
                e.Handled      = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonUp)
            {
                RightMouseDown = false;
                e.Handled      = focusedWindow;
            }
            // Middle mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonDown)
            {
                MiddleMouseDown = true;
                e.Handled       = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonUp)
            {
                MiddleMouseDown = false;
                e.Handled       = focusedWindow;
            }
            #endregion
            #region Mouse move
            else if (e.MouseState == GlobalMouseHook.MouseState.Move)
            {
                var screen      = Screen.FromHandle(RemotePlayProcess.MainWindowHandle);
                var workingArea = screen.WorkingArea;
                var referenceX  = workingArea.Width / 2;
                var referenceY  = workingArea.Height / 2;

                var rawX = e.MouseData.Point.X;
                var rawY = e.MouseData.Point.Y;

                #region Store mouse stroke
                var newStroke = new MouseStroke()
                {
                    Timestamp = DateTime.Now,
                    RawData   = e,
                    DidMoved  = true,
                    X         = rawX,
                    Y         = rawY
                };

                if (CurrentMouseStroke != null)
                {
                    double deltaTime = (newStroke.Timestamp - CurrentMouseStroke.Timestamp).TotalSeconds;

                    if (deltaTime != 0) // moving too fast causes NaN
                    {
                        // Velocity is relative to the middle of the screen
                        newStroke.VelocityX = (CurrentMouseStroke.X - 1440) / deltaTime;
                        newStroke.VelocityY = (CurrentMouseStroke.Y - 870) / deltaTime;

                        if (MouseInvertXAxis)
                        {
                            newStroke.VelocityX = -newStroke.VelocityX;
                        }
                        if (MouseInvertYAxis)
                        {
                            newStroke.VelocityY = -newStroke.VelocityY;
                        }

                        newStroke.VelocityX = (newStroke.VelocityX * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;
                        newStroke.VelocityY = (newStroke.VelocityY * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;

                        // Add quadratic scaling
//                        newStroke.VelocityX *= Math.Abs(newStroke.VelocityX/8);
//                        newStroke.VelocityY *= Math.Abs(newStroke.VelocityY/8);

                        if (Math.Abs(newStroke.VelocityX) > 0.0)
                        {
                            newStroke.VelocityX += (Math.Sign(newStroke.VelocityX) * 22);
                        }
                        if (Math.Abs(newStroke.VelocityY) > 0.0)
                        {
                            newStroke.VelocityY += (Math.Sign(newStroke.VelocityY) * 22);
                        }

                        TempCurrentX += newStroke.VelocityX;
                        TempCurrentY += newStroke.VelocityY;

//                        Console.WriteLine("RefX: " + referenceX + " - RefY: " + referenceY);
//                        Console.WriteLine("X: " + CurrentMouseStroke.X + " - Y: " + CurrentMouseStroke.Y);
//                        Console.WriteLine("VelX: " + newStroke.VelocityX + " - VelY: " + newStroke.VelocityY);
//                        Console.WriteLine("rawX: " + rawX + " - rawY: " + rawY);
                        // Reset the mouse to the reference position
                    }
                }

                CurrentMouseStroke = newStroke;
                #endregion

                #region Adjust cursor position;
                RemapperUtility.SetCursorPosition(referenceX, referenceY);
                e.Handled = true;

                #endregion
                #endregion
            }
        }