ControlGetFocus

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

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

Parameters

WinTitle

Type: String, Integer or Object

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

WinText

Type: String

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

Type: String

Windows whose titles include this value will not be considered.

ExcludeText

Type: String

Windows whose text include this value will not be considered.

Return Value

Type: Integer

This function returns the window handle (HWND) of the focused control.

If none of the target window's controls has focus, the return value is 0.

Error Handling

An exception is thrown if the window or control could not be found, or there was a problem determining the focus.

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.

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

Related

ControlFocus, Control functions

Examples

#1: Get the HWND and ClassNN of the active window's focused control.

FocusedHwnd := ControlGetFocus("A")
FocusedClassNN := ControlGetClassNN(FocusedHwnd)
MsgBox 'Control with focus = {Hwnd: ' FocusedHwnd ', ClassNN: "' FocusedClassNN '"}'