MouseClick

Clicks or holds down a mouse button, or turns the mouse wheel. Note: The Click command is generally more flexible and easier to use.

MouseClick , WhichButton, X, Y, ClickCount, Speed, DownOrUp, Relative

Parameters

WhichButton

If blank or omitted, it defaults to Left (the left mouse button). Otherwise, specify the button to click or the rotate/push direction of the mouse wheel.

Button: Left, Right, Middle (or just the first letter of each of these); or X1 (fourth button) or X2 (fifth button). For example: MouseClick, X1.

Mouse wheel: Specify WheelUp or WU to turn the wheel upward (away from you); specify WheelDown or WD to turn the wheel downward (toward you). [v1.0.48+]: Specify WheelLeft (or WL) or WheelRight (or WR) to push the wheel left or right, respectively (but these have no effect on operating systems older than Windows Vista). ClickCount is the number of notches to turn the wheel.

To compensate automatically for cases where the user has swapped the left and right mouse buttons via the system's control panel, use the Click command instead.

X, Y

If blank or omitted, the cursor's current position is used. Otherwise, specify the X and Y coordinates to which the mouse cursor is moved prior to clicking, which can be expressions. Coordinates are relative to the active window unless CoordMode was used to change that.

ClickCount

If blank or omitted, it defaults to 1. Otherwise, specify the number of times to click the mouse button or turn the mouse wheel, which can be an expression.

Speed

If blank or omitted, the default speed (as set by SetDefaultMouseSpeed or 2 otherwise) will be used. Otherwise, specify the speed to move the mouse in the range 0 (fastest) to 100 (slowest), which can be an expression. A speed of 0 will move the mouse instantly.

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).

DownOrUp

If blank or omitted, each click consists of a down-event followed by an up-event. Otherwise, specify one of the following letters:

D: Press the mouse button down but do not release it (i.e. generate a down-event).

U: Release the mouse button (i.e. generate an up-event).

Relative

If blank or omitted, the X and Y coordinates will be used for absolute positioning. Otherwise, specify the following 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 Click command is recommended over MouseClick because:

  1. It automatically compensates when the left and right mouse buttons are swapped via the control panel.
  2. It is generally easier to use.

To perform a shift-click or control-click, use the Send command before and after the operation as shown in these examples:

; Example #1: 
Send, {Control down}
MouseClick, left, 55, 233
Send, {Control up}
; Example #2:
Send, {Shift down}
MouseClick, left, 55, 233
Send, {Shift up}

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).

Some applications do not obey a ClickCount higher than 1 for the mouse wheel. For them, use a Loop such as the following:

Loop, 5
    MouseClick, WheelUp

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 click-down and click-up of the mouse (except for SendInput mode and for turning the mouse wheel). Use SetMouseDelay to change the length of the delay.

CoordMode, SendMode, SetDefaultMouseSpeed, SetMouseDelay, Click, MouseClickDrag, MouseGetPos, MouseMove, ControlClick, BlockInput

Examples

Double-clicks at the current mouse position.

MouseClick, left
MouseClick, left

Same as above.

MouseClick, left,,, 2

Moves the mouse cursor to a specific position, then right-clicks once.

MouseClick, right, 200, 300

Simulates the turning of the mouse wheel.

#up::MouseClick, WheelUp,,, 2  ; Turn it by two notches.
#down::MouseClick, WheelDown,,, 2