Editable (UIA add-on)

Post your working scripts, libraries and tools.
Descolada
Posts: 1123
Joined: 23 Dec 2021, 02:30

Editable (UIA add-on)

Post by Descolada » 31 Mar 2023, 15:00

This is more of a proof of concept (or something to build upon) rather than something dependable to be used in actual scripts.

Editable class available on GitHub

Overview

Editable class can be used to interact with editable elements such as textboxes and manipulate their content. It requires UIA.ahk to be used.

Editable() returns an UIA element, which in addition to regular UIA properties and methods has some additional text-related ones:

Code: Select all

Editable().Value       => gets or sets the current text
Editable().Selection   => returns an object {start, end, text} with the current selection text, and start and end offsets
Editable().CaretOffset => returns the position of the caret relative to the beginning of the text
Editable().Select(from, to)      => selects text from offsets (starting from beginning of the element)
Editable().Insert(text, offset?) => inserts text, by default to the current caret position
Calling the class without any arguments ( Editable() ) returns the UIA element for the element with keyboard focus (caret).
Calling the class with an UIA textual element ( Editable(element) ) returns an Editable for the provided element.

Editable static method GetCaretPos can be used to get the current screen coordinates for the caret: Editable.GetCaretPos(&x:=0, &y:=0)

Examples

Provided in the Editables.ahk file in GitHub.

Known limitations

1. Doesn't work in Chrome or Edge URL bar when autosuggestions are shown
2. Doesn't work in Steam
3. In some Qt apps (eg qBittorrent), when inserting text to the end of the editable, then the caret is positioned incorrectly
4. Discord doesn't handle inserted text properly, ending up with undeletable text (at least in some elements)
5. Cannot access windows ran as administrators, unless the script is also ran as admin or with UIAccess
6. Probably many more limitations...

Return to “Scripts and Functions (v2)”