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, Relative



Type: String

The button to click: Left, Right, Middle (or just the first letter of each of these). Specify X1 for the fourth button and X2 for the fifth. For example: MouseClickDrag "X1", ....

Left and Right correspond to the primary button and secondary button. If the user swaps the buttons via system settings, the physical positions of the buttons are swapped but the effect stays the same.

X1, Y1

Type: Integer

The x/y coordinates of the drag's starting position (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

Type: Integer

The x/y coordinates to drag the mouse to (that is, while the button is held down). Coordinates are relative to the active window unless CoordMode was used to change that.


Type: Integer

The speed to move the mouse in the range 0 (fastest) to 100 (slowest).

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} or SendMode Event (optionally in conjuction with BlockInput).


Type: String

If omitted, the X and Y coordinates will be treated as absolute values. To change this behavior, specify the following 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 "Left", 5, 5, 10, 10, , "R".


This function uses the sending method set by SendMode.

Dragging can also be done via the various Send functions, which is more flexible because the mode can be specified via the function name. For example:

SendEvent "{Click 6, 52, down}{click 45, 52, up}"

Another advantage of the method above is that unlike MouseClickDrag, it automatically compensates when the user has swapped the left and right mouse buttons via the system's control panel.

The SendPlay mode is able to successfully generate mouse events in a broader variety of games than the other modes. However, dragging via SendPlay might not work in RichEdit controls (and possibly others) such as those of WordPad and Metapad.

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 function can be used to prevent any physical mouse activity by the user from disrupting the simulated mouse events produced by the mouse functions. 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 click-down and click-up of the mouse (except for SendInput mode). This delay also occurs after the movement of the mouse during the drag operation. Use SetMouseDelay to change the length of the delay.


CoordMode, SendMode, SetDefaultMouseSpeed, SetMouseDelay, Click, MouseClick, MouseGetPos, MouseMove, BlockInput



MouseClickDrag "left", 0, 200, 600, 400

#2: The following example opens MS Paint and draws a little house:

Run "mspaint.exe"
if !WinWaitActive("ahk_class MSPaintApp",, 2)
MouseClickDrag "L", 150, 350, 150, 250
MouseClickDrag "L", 150, 250, 200, 200
MouseClickDrag "L", 200, 200, 250, 250
MouseClickDrag "L", 250, 250, 150, 250
MouseClickDrag "L", 150, 250, 250, 350
MouseClickDrag "L", 250, 350, 250, 250
MouseClickDrag "L", 250, 250, 150, 350
MouseClickDrag "L", 150, 350, 250, 350