Returns the ControlRef# of the control that has keyboard focus within a specified window.
ControlGetFocus ( "title" [, "text"] )
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. |
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. |
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
; 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 WinWait.
WinClose($hWnd)
EndFunc ;==>Example