ControlGetFocus

Retrieves which control of the target window has input focus, if any.

ClassNN := ControlGetFocus(WinTitle, WinText, ExcludeTitle, ExcludeText)

Parameters

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.

Return Value

Returns the ClassNN of the control; that is, the control's classname followed by its sequence number within its parent window, e.g. Button12.

If there was a problem or none of the target window's controls has focus, the return value is blank.

ErrorLevel

ErrorLevel is set to 1 if there was a problem determining the focus or 0 otherwise. An ErrorLevel of 1 typically indicates that the window does not exist.

Remarks

The control retrieved by this function is the one that has keyboard focus, that is, the one that would receive keystrokes if the user were to type any.

The target window must be active to have a focused control, but even the active window may lack a focused control. If the target window was found but none of its controls have focus, ErrorLevel is set to 0 and the return value is blank.

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

Related

ControlFocus, ControlMove, ControlClick, ControlGetText, ControlSetText, ControlSend

Example

Focused := ControlGetFocus("Untitled - Notepad")
if ErrorLevel
    MsgBox "The target window doesn't exist."
else
    MsgBox "Control with focus = " Focused