MouseMove
Moves the mouse cursor.
MouseMove, X, Y , Speed, R
Parameters
- X, Y
The x/y coordinates to move the mouse to, which can be expressions. Coordinates are relative to the active window unless CoordMode was used to change that.
- Speed
The speed to move the mouse in the range 0 (fastest) to 100 (slowest), which can be an expression.
Note: A speed of 0 will move the mouse instantly.
If omitted, the default speed (as set by SetDefaultMouseSpeed or 2 otherwise) will be used.
Speed is ignored for SendInput/Play modes; they move the mouse instantaneously (though SetMouseDelay has a mode that applies to SendPlay). To visually move the mouse more slowly -- such as a script that performs a demonstration for an audience -- use
SendEvent {Click 100, 200}
orSendMode Event
(optionally in conjuction with BlockInput).- R
If this parameter is the letter R, the X and Y coordinates will be treated as offsets from the current mouse position. In other words, the cursor will be moved from its current position by X pixels to the right (left if negative) and Y pixels down (up if negative).
Remarks
This command uses the sending method set by SendMode.
The SendPlay mode is able to successfully generate mouse events in a broader variety of games than the other modes. In addition, some applications and games may have trouble tracking the mouse if it moves too quickly. The speed parameter or SetDefaultMouseSpeed can be used to reduce the speed (in the default SendEvent mode only).
The BlockInput command can be used to prevent any physical mouse activity by the user from disrupting the simulated mouse events produced by the mouse commands. However, this is generally not needed for the SendInput/Play modes because they automatically postpone the user's physical mouse activity until afterward.
There is an automatic delay after every movement of the mouse (except for SendInput mode). Use SetMouseDelay to change the length of the delay.
The following is an alternate way to move the mouse cursor that may work better in certain multi-monitor configurations:
DllCall("SetCursorPos", int, 100, int, 400) ; The first number is the X-coordinate and the second is the Y (relative to the screen).
On a related note, the mouse cursor can be temporarily hidden via the hide-cursor example.
Related
CoordMode, SendMode, SetDefaultMouseSpeed, SetMouseDelay, Click, MouseClick, MouseClickDrag, MouseGetPos, BlockInput
Example
; Move the mouse to a new position: MouseMove, 200, 100 ; Move the mouse slowly (speed 50 vs. 2) by 20 pixels to the right and 30 pixels down ; from its current location: MouseMove, 20, 30, 50, R