WinGetText

Retrieves the text from the specified window.

OutputVar := WinGetText(WinTitle, WinText, ExcludeTitle, ExcludeText)

Parameters

OutputVar

The name of the variable in which to store the retrieved text.

WinTitle

A window title or other criteria identifying the target window. See WinTitle.

WinText

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.

ExcludeTitle

Windows whose titles include this value will not be considered.

ExcludeText

Windows whose text include this value will not be considered.

ErrorLevel

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

Remarks

The text retrieved is generally the same as what Window Spy shows for that window. However, if DetectHiddenText has been turned off, hidden text is omitted from OutputVar.

Each text element ends with a carriage return and linefeed (CR+LF), which can be represented in the script as `r`n. To extract individual lines or substrings, use functions such as InStr and SubStr. A parsing loop can also be used to examine each line or word one by one.

If the retrieved text appears to be truncated (incomplete), try using VarSetCapacity(OutputVar, 55) prior to WinGetText [replace 55 with a size that is considerably longer than the truncated text]. This is necessary because some applications do not respond properly to the WM_GETTEXTLENGTH message, which causes AutoHotkey to make the output variable too small to fit all the text.

This function might use a large amount of RAM if the target window (e.g. an editor with a large document open) contains a large quantity of text. To avoid this, it might be possible to retrieve only portions of the window's text by using ControlGetText instead. In any case, a variable's memory can be freed later by assigning it to nothing, i.e. OutputVar := "".

To retrieve a list of all controls in a window, follow this example: OutputVar := WinGetControls(WinTitle)

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

Related

ControlGetText, WinGetTitle, WinGetPos

Example

Run "calc.exe"
WinWait "Calculator"
MsgBox "The text is:`n" WinGetText()  ; The window found above will be used.