Control Functions

Functions to retrieve information about a control, or make a variety of changes to a control. Click on a function name for details.

Function Description
ControlAddItem Adds the specified string as a new entry at the bottom of a ListBox or ComboBox.
ControlChoose Sets the selection in a ListBox or ComboBox to be the specified entry number.
ControlChooseString Sets the selection in a ListBox or ComboBox to be the first entry whose leading part matches the specified string.
ControlClick Sends a mouse button or mouse wheel event to a control.
ControlDeleteItem Deletes the specified entry number from a ListBox or ComboBox.
ControlEditPaste Pastes the specified string at the caret (text insertion point) in an Edit control.
ControlFindItem Returns the entry number of a ListBox or ComboBox that is a complete match for the specified string.
ControlFocus Sets input focus to a given control on a window.
ControlGetChecked Returns a non-zero value if the checkbox or radio button is checked.
ControlGetChoice Returns the name of the currently selected entry in a ListBox or ComboBox.
ControlGetClassNN Returns the ClassNN (class name and sequence number) of the specified control.
ControlGetCurrentCol Returns the column number in an Edit control where the caret (text insertion point) resides.
ControlGetCurrentLine Returns the line number in an Edit control where the caret (text insert point) resides.
ControlGetEnabled Returns a non-zero value if the specified control is enabled.
ControlGetFocus Retrieves which control of the target window has keyboard focus, if any.
ControlGetHwnd Returns the unique ID number of the specified control.
ControlGetLine Returns the text of the specified line in an Edit control.
ControlGetLineCount Returns the number of lines in an Edit control.
ControlGetList Returns a list of items/rows from a ListView, ListBox, ComboBox, or DropDownList.
ControlGetPos Retrieves the position and size of a control.
ControlGetSelected Returns the selected text in an Edit control.
ControlGetStyle
ControlGetExStyle
Returns an integer representing the style or extended style of the specified control.
ControlGetTab Returns the position number of the selected tab in a SysTabControl32.
ControlGetText Retrieves text from a control.
ControlGetVisible Returns a non-zero value if the specified control is visible.
ControlHide Hides the specified control.
ControlHideDropDown Hides the drop-down list of a ComboBox control.
ControlMove Moves or resizes a control.
ControlSend
ControlSendText
Sends simulated keystrokes or text to a window or control.
ControlSetChecked Turns on (checks) or turns off (unchecks) a checkbox or radio button.
ControlSetEnabled Enables or disables the specified control.
ControlSetStyle
ControlSetExStyle
Changes the style or extended style of the specified control, respectively.
ControlSetTab Selects the specified position number of a tab in a SysTabControl32.
ControlSetText Changes the text of a control.
ControlShow Shows the specified control if it was previously hidden.
ControlShowDropDown Shows the drop-down list of a ComboBox control.

The Control Parameter

Functions which operate on individual controls have a parameter named Control which supports a few different ways to identify the control. The Control parameter can be one of the following:

ClassNN (String): The ClassNN (classname and instance number) of the control, which can be determined via Window Spy. For example "Edit1" is the first control with classname "Edit".

Text (String): The control's text. The matching behavior is determined by SetTitleMatchMode.

HWND (Integer): The control's HWND, which is typically retrieved via ControlGetHwnd, MouseGetPos, or DllCall. This also works on hidden controls even when DetectHiddenWindows is Off. Any subsequent window parameters are ignored.

Object: An object of any type with a Hwnd property, such as a GuiControl. An exception is thrown if the object has no Hwnd property or it does not return a pure integer. Any subsequent window parameters are ignored.

Omitted: A few functions are able to operate on either a control or a top-level window. Omitting the Control parameter causes the function to use the target window (specified by WinTitle) instead of one of its controls. For example, ControlSend can send keyboard messages directly to the window.

Error Handling

ErrorLevel is set to 1 if there was a problem or 0 otherwise. Unless specified otherwise, each function also returns 1 (true) to indicate success or 0 (false) to indicate failure.

An exception is thrown if invalid parameters are detected.

Remarks

To improve reliability, a delay is done automatically after each use of a Control function that changes a control (except for ControlSetStyle and ControlSetExStyle). That delay can be changed via SetControlDelay or by assigning a value to A_ControlDelay. For details, see SetControlDelay remarks.

To discover the ClassNN or HWND of the control that the mouse is currently hovering over, use MouseGetPos.

To retrieve a list of all controls in a window, use WinGetControls or WinGetControlsHwnd.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

Related

SetControlDelay, Win functions, GuiControl object (for controls created by the script)