Ejemplo n.º 1
0
 public void RecordMouseMovementChange(Coordinates mouseCoordinates)
 {
     if (IsRecordingChanges)
     {
         if (LastMouseMoveCoordinates.Count == 0 || mouseCoordinates != LastMouseMoveCoordinates[^ 1])
         {
             LastMouseMoveCoordinates.Add(mouseCoordinates);
             MousePositionChanged?.Invoke(this, new MouseMovementEventArgs(mouseCoordinates));
         }
     }
 }
Ejemplo n.º 2
0
        private void UpdateMouseInfo()
        {
            var mousePosition = GetCursorPosition();

            if (_previousMousePosition != mousePosition)
            {
                _previousMousePosition = mousePosition;
                MousePositionChanged?.Invoke(this, mousePosition);
            }

            var color = GetPixelColor(mousePosition);

            if (_previousColor != color)
            {
                _previousColor = color;
                MouseColorChanged?.Invoke(this, color);
            }
        }
Ejemplo n.º 3
0
        private static IntPtr HookCallback(
            int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            // && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
            {
                MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                // Console.WriteLine("Mouse move: " + hookStruct.pt.x + ", " + hookStruct.pt.y);

                MousePositionChanged?.Invoke(hookStruct.pt.x, hookStruct.pt.y);

                if (MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
                {
                    MouseButtonClicked?.Invoke(0);
                }
                if (MouseMessages.WM_RBUTTONDOWN == (MouseMessages)wParam)
                {
                    MouseButtonClicked?.Invoke(1);
                }
            }
            return(CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check for any change on the mouse and perform the right actions.
        /// </summary>
        private static void CheckForMouseChange()
        {
            MouseButton theMouseButtonDown = GetPressedMouseButton();

            // MouseChanged event: Check if any mouse button was clicked.
            if (AnyMousePressed())
            {
                MouseChanged?.Invoke(null, currentMouseState);
            }

            // MouseDown event: Check if any mouse button was clicked.
            if (theMouseButtonDown != MouseButton.None)
            {
                MousePressed?.Invoke(null, new MouseEventArgs(theMouseButtonDown, currentMouseState.Position, currentMouseState.ScrollWheelValue));
            }

            // MousePositionChanged event: Check if the cursor moved and what mouse button was held while it was.
            Point cursorDelta = GetDeltaMouseMovement();

            if (cursorDelta.X != 0 && cursorDelta.Y != 0)
            {
                MousePositionChanged?.Invoke(null, new MousePositionEventArgs(theMouseButtonDown, currentMouseState.Position, previousMouseState.Position));
            }
        }
Ejemplo n.º 5
0
 private void OnMousePositionUpdate(MousePosition position)
 {
     MousePositionChanged?.Invoke(position);
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Plain mouse move, does not affect mouse drag recordings.
 /// </summary>
 public void MouseMoved(Coordinates mouseCoordinates)
 {
     MousePositionChanged?.Invoke(this, new MouseMovementEventArgs(mouseCoordinates));
 }