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

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



Type: String, Integer or Object

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


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.


Type: String

Windows whose titles include this value will not be considered.


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

A TargetError is thrown if there is a problem determining the target window or control.

An OSError is thrown if there is a problem determining the focus.


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.

ControlFocus, Control functions


Reports 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 '"}'