Control wrapper

This wrapper allows simple access to another application’s controls (i.e. buttons and other widgets).

classes

Control

class ahk.Control(script, title='', text='', extitle='', extext='', store=True)

Wrapper around ahk window control commands.

Initialize a new Control object.

Stores information about the window who’s controls you will manipulate.

Parameters:
  • script (ahk.Script instance) – Script object to use internally.
  • title (str (default="")) – Partial window title text to match.
  • text (str (default="")) – Partial window text to match.
  • extitle (str (default="")) – Partial window title text to avoid.
  • extext (str (default="")) – Partial window text to avoid.
  • store (bool) – Whether to cache the found window.
Raises:

NameError if store=True but a matching window can’t be found.

set_delay(control='', key='')

Set the control or key delay used by this Control object.

Either the control delay, key delay, or both may be set. Setting either to None will disable the local delay setting. See AHK docs for more details.

Parameters:
  • control (float or None) – The delay to use when modifying a control.
  • key (float or None) – The delay to use for send-ing key events.
click(*args, **kwargs)

Sends mouse input to a control.

The control arg can be a class name, window handle, or text string. Alternately pos as a (x, y) tuple may be provided indicating the mouse coordinates relative to the top-left corner of the application window in which to click. If both control and pos are provided pos is interpreted relative to the indicated control.

Default is a single left click, but you can send left/right/middle, wheel up or down left or right with a repeat count. See AHK docs for more details.

Parameters:
  • control (str) – The class, HWND, or text of the control to click.
  • pos (tuple (indexable)) – The relative coordinates of at which to click.
  • button (str) – The name of the button to be clicked.
  • count (int) – Number of times it should be clicked.
  • options (str) – Optional arguments.
send(*args, **kwargs)

Send keystrokes to a control.

See AHK docs for more details.

Parameters:
  • control (str) – The class, HWND, or text of the control to send to.
  • keys (str) – Keystrokes in the same format as ahk.Script.send.
  • raw (bool (default False)) – Toggle raw input mode.
setText(*args, **kwargs)

Set the text content of a control.

See AHK docs for more details.

Parameters:
  • control (str) – The class, HWND, or text of the control to be changed.
  • value (str) – New text to substitute into the control.
get_choices(control='')

Retrieve the available values from a ComboBox.

Parameters:control (str) – The class, HWND, or text of the control to be checked.
Returns:A list of value strings (in order).
get_chosen(control='')

Retrieve the selected value from a ComboBox.

Parameters:control (str) – The class, HWND, or text of the control to be checked.
Returns:Selected value as a string.
choose(*args, **kwargs)

Pick an item from a listbox or combobox.

See AHK docs for more details.

Parameters:
  • control (str) – The class, HWND, or text of the control to be changed.
  • value (str or int (default="")) – Partial text of choice or choice index (starting from 1).
is_checked(control='')

Check if a checkbox control is checked.

Parameters:control (str) – The class, HWND, or text of the control to be checked.
Returns:True if it was checked, else False.
check(*args, **kwargs)

Pick an item from a listbox or combobox.

The state can be set to checked (True), unchecked (False), or toggle (None), default is toggle. See AHK docs for more details.

Parameters:
  • control (str) – The class, HWND, or text of the control to be changed.
  • state (bool or None) – The desired checked state.