Example #1
0
        /// <summary>
        /// Executes a set of mouse events at a specific position on the screen
        /// </summary>
        /// <param name="xPos">x position in screen coordinates</param>
        /// <param name="yPos">y position in screen coordinates</param>
        /// <param name="retainNewPosition">determines if the cursor should stay at the event position, or reset to the starting before the events</param>
        /// <param name="mouseEvents">the mouse events to execute</param>
        private static void ExecuteMouseEvents(int xPos, int yPos, bool retainNewPosition, params MouseEvent[] mouseEvents)
        {
            Point currPos = GetMouseInfo().Position;

            // First move the cursor (must be at the position before executing the events)
            MoveTo(xPos, yPos);

            // Send all of the mouse events
            foreach (MouseEvent mEvent in mouseEvents)
            {
                WinCursorInterop.SendMouseEvent(mEvent, xPos, yPos);
            }

            if (!retainNewPosition)
            {
                // Reset to original mouse position before the events
                MoveTo(currPos.X, currPos.Y);
            }
        }
Example #2
0
 /// <summary>
 /// Retrieves the current mouse information which contains the screen position and cursor type
 /// </summary>
 /// <returns>Point struct containing current x-y cursor position in screen coordinates</returns>
 public static MouseInfo GetMouseInfo()
 {
     WinCursorInterop.CursorInfo cursorInfo = WinCursorInterop.GetCursorInfo();
     return(new MouseInfo(cursorInfo.ptScreenPos, cursorInfo.hCursor));
 }
Example #3
0
 /// <summary>
 /// Moves the mouse position to the specified xy position in screen coordinates
 /// </summary>
 /// <param name="xPos">x position in screen coordinates</param>
 /// <param name="yPos">y position in screen coordinates</param>
 public static void MoveTo(int xPos, int yPos)
 {
     WinCursorInterop.SetCursorPosition(xPos, yPos);
 }