Clicks and holds the specified mouse button, moves the mouse to the destination coordinates, then releases the button.
MouseClickDrag, WhichButton, X1, Y1, X2, Y2 [, Speed, R] |
Parameters
WhichButton | The button to click: Left, Right, Middle (or just the first letter of each of these). The fourth and fifth mouse buttons are supported on Windows 2000/XP or later: Specify X1 for the fourth button and X2 for the fifth. For example: MouseClickDrag, X1, ... |
X1, Y1 | The x/y coordinates of the drag's starting position, which can be expressions (the mouse will be moved to these coordinates right before the drag is started). Coordinates are relative to the active window unless CoordMode was used to change that. If omitted, the mouse's current position is used. |
X2, Y2 | The x/y coordinates to drag the mouse to (that is, while the button is held down), 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. |
R | If this parameter is the letter R, the X1 and Y1 coordinates will be treated as offsets from the current mouse position. In other words, the cursor will be moved from its current position by X1 pixels to the right (left if negative) and Y1 pixels down (up if negative). Similarly, the X2 and Y2 coordinates will be treated as offsets from the X1 and Y1 coordinates. For example, the following would first move the cursor down and to the right by 5 pixels from its starting position, and then drag it from that position down and to the right by 10 pixels: MouseClickDrag, 5, 5, 10, 10, , R |
Remarks
Some applications such as certain full-screen games may have trouble tracking the mouse if it moves too quickly. The Speed parameter or SetDefaultMouseSpeed can be used to reduce the speed.
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.
There is an automatic delay after every click-down and click-up of the mouse. This delay also occurs after the movement of the mouse during the drag operation. Use SetMouseDelay to change the length of the delay.
Related
CoordMode, SetDefaultMouseSpeed, SetMouseDelay, MouseClick, MouseGetPos, MouseMove, BlockInput
Example
MouseClickDrag, left, 0, 200, 600, 400 ; The following example opens MS Paint and draws a little house: Run, mspaint.exe WinWaitActive, ahk_class MSPaintApp,, 2 if ErrorLevel return MouseClickDrag, L, 150, 250, 150, 150 MouseClickDrag, L, 150, 150, 200, 100 MouseClickDrag, L, 200, 100, 250, 150 MouseClickDrag, L, 250, 150, 150, 150 MouseClickDrag, L, 150, 150, 250, 250 MouseClickDrag, L, 250, 250, 250, 150 MouseClickDrag, L, 250, 150, 150, 250 MouseClickDrag, L, 150, 250, 250, 250