# Function Reference

# ControlGetFocus

Returns the ControlRef# of the control that has keyboard focus within a specified window.

ControlGetFocus ( "title" [, "text"] )

## Parameters

title | The title/hWnd/class of the window to access. See Title special definition.
text | [optional] The text of the window to access. See Text special definition.

## Return Value

Success: | the ClassNameNN of the control that has keyboard focus within a specified window.
Failure: | "" (empty string) and sets the @error flag to 1 if window is not found.

## Related

ControlCommand, ControlFocus

## Example

    #include <MsgBoxConstants.au3>

    Example()

    Func Example()
        ; Run Notepad
        Run("notepad.exe")

        Local $hWnd = WinWaitActive("[CLASS:Notepad]", "")

        ; Retrieve the control that has keyboard focus in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetFocus.
        Local $sControl = ControlGetFocus($hWnd)

        ; Display the control that has keyboard focus.
        MsgBox($MB_SYSTEMMODAL, "", "The control that has keyboard focus in Notepad is: " & $sControl)

        ; Close the Notepad window using the handle returned by WinWaitActive.
        WinClose($hWnd)
    EndFunc   ;==>Example