AutoIt WinActivate Function
How to activate windows using AutoIts WinActivate function.
Edited: 2017-03-25 01:53
AutoIt's WinActivate function is used to activate a window, or change the focus to another window, so one can interact with it. A window which is in focus, might still be covered by a window that is set to always on top – so be careful.
If you want to check if a window is active, use AutoIt's WinActive function instead.
To get the title info from the window you want to activate, use the AutoIt Window Info Tool. You will find the info you need in the window tab.
Parameters
Window | Title, hWnd or class of the window to check. |
Text | The text of the window to check. Default is an empty string. |
Return Value
Success | The handle of the window. |
Failure | 0 |
WinActivate Example
WinActivate("[CLASS:SpotifyMainWindow]")
Sometimes you may need to wait for the window to appear, before you attempt to activate it, and that's where the WinWait function comes into play. The WinWait function will pause the script, until a specified window appears. In this case it will wait for 10 seconds, if the window doesn't appear inside of those ten seconds, it will exit the script.
$hWnd = WinWait("[CLASS:SpotifyMainWindow]", "", 10) WinActivate($hWnd)
If you don't want it to exit, you can just remove the optional timeout parameter.
$hWnd = WinWait("[CLASS:SpotifyMainWindow]") WinActivate($hWnd)
Tell us what you think: