Sends a mouse button or mouse wheel event to a control.
ControlClick Control-or-Pos, WinTitle, WinText, WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText
Type: String, Integer or Object
If this parameter is omitted, the target window itself will be clicked. Otherwise, one of the two modes below will be used.
Mode 1 (Position): Specify the X and Y coordinates relative to the upper left corner of the target window's client area. The X coordinate must precede the Y coordinate and there must be at least one space or tab between them. For example:
X55 Y33. If there is a control at the specified coordinates, it will be sent the click-event at those exact coordinates. If there is no control, the target window itself will be sent the event (which might have no effect depending on the nature of the window).
Note: In mode 1, the X and Y option letters of the Options parameter are ignored.
Mode 2 (Control): Specify the control's ClassNN, text or HWND, or an object with a
Hwnd property. For details, see The Control Parameter.
By default, mode 2 takes precedence over mode 1. For example, in the unlikely event that there is a control whose text or ClassNN has the format "Xnnn Ynnn", it would be acted upon by Mode 2. To override this and use mode 1 unconditionally, specify the word Pos in Options as in the following example:
ControlClick "x255 y152", WinTitle,,,, "Pos".
Type: String, Integer or Object
A window title or other criteria identifying the target window. See WinTitle.
If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.
The button to click: LEFT, RIGHT, MIDDLE (or just the first letter of each of these). If omitted or blank, the LEFT button will be used.
X1 (XButton1, the 4th mouse button) and X2 (XButton2, the 5th mouse button) are also supported.
WheelUp (or WU), WheelDown (or WD), WheelLeft (or WL) and WheelRight (or WR) are also supported. In this case, ClickCount is the number of notches to turn the wheel.
The number of clicks to send. If omitted or blank, 1 click is sent.
A series of zero or more of the following option letters. For example: d x50 y25
NA: May improve reliability. See reliability below.
D: Press the mouse button down but do not release it (i.e. generate a down-event). If both the D and U options are absent, a complete click (down and up) will be sent.
U: Release the mouse button (i.e. generate an up-event). This option should not be present if the D option is already present (and vice versa).
Pos: Specify the word Pos anywhere in Options to unconditionally use the X/Y positioning mode as described in the Control-or-Pos parameter above.
Xn: Specify for n the X position to click at, relative to the control's upper left corner. If unspecified, the click will occur at the horizontal-center of the control.
Yn: Specify for n the Y position to click at, relative to the control's upper left corner. If unspecified, the click will occur at the vertical-center of the control.
Use decimal (not hexadecimal) numbers for the X and Y options.
Windows whose titles include this value will not be considered.
Windows whose text include this value will not be considered.
An exception is thrown in the following cases:
To improve reliability -- especially during times when the user is physically moving the mouse during the ControlClick -- one or both of the following may help:
SetControlDelay -1 prior to ControlClick. This avoids holding the mouse button down during the click, which in turn reduces interference from the user's physical movement of the mouse.
2) Specify the string NA anywhere in the sixth parameter (Options) as shown below:
SetControlDelay -1 ControlClick "Toolbar321", WinTitle,,,, "NA"
NA avoids marking the target window as active and avoids merging its input processing with that of the script, which may prevent physical movement of the mouse from interfering (but usually only when the target window is not active). However, this method might not work for all types of windows and controls.
Not all applications obey a ClickCount higher than 1 for turning the mouse wheel. For those applications, use a Loop to turn the wheel more than one notch as in this example, which turns it 5 notches:
Loop 5 ControlClick Control, WinTitle, WinText, "WheelUp"
Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.
SetControlDelay, Control functions, Click
ControlClick "OK", "Some Window Title" ; Clicks the OK button ControlClick "x55 y77", WinTitle ; Clicks at a set of coordinates. Note the lack of a comma between X and Y.
#2: The following method may improve reliability and reduce side effects:
SetControlDelay -1 ControlClick "Toolbar321", WinTitle,,,, "NA x192 y10" ; Clicks in NA mode at coordinates that are relative to a named control.