Home > FAQ > Useful Basic Tasks when writing a script > How do I find the window which has the focus?

How do I find the window which has the focus?

Focus$() function returns the window name of the focused window. And so this code:
UseWindow(focus$())
waits until the focused window is ready for receiving actions.
 
If multiple instances of the same window are displayed on screen, you can use TopInstance() function to get the instance number of the window on top. And so this code:
UseWindow(focus$(),TopInstance())
waits until the focused window for the instance on top. 

Top$() function returns the window name of the window on top. It can be too used in conjunction with TopInstance() function.