MouseClick()

Auto Hotkey

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, "D|U", "R"

Parameters

WhichButton

The button to click: Left (default), Right, Middle (or just the first letter of each of these); or the fourth or fifth mouse button (X1 or X2). For example: MouseClick, X1. This parameter may be omitted, in which case it defaults to Left.

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

The x/y coordinates to which the mouse cursor is moved prior to clicking. Coordinates are relative to the active window unless CoordMode was used to change that. If omitted, the cursor's current position is used.

ClickCount

The number of times to click the mouse. If omitted, the button is clicked once.

Speed

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

D|U

If this parameter is omitted, each click will consist of a "down" event followed by an "up" event. Alternatively:
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).

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

Related

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

Examples

; Double click at the current mouse pos:
MouseClick, left
MouseClick, left

; Same as above:
MouseClick, left, , , 2

; Move to specified coordinates then right-click once:
MouseClick, right, 200, 300

; Here are two hotkeys that simulate the turning of the mouse wheel:
#up::MouseClick, WheelUp, , , 2  ; Turn it by two notches.
#down::MouseClick, WheelDown, , , 2