Share via:

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.

Screenshot showing the Window tab of the AutoIt Window Info tool.


WindowTitle, hWnd or class of the window to check.
TextThe text of the window to check. Default is an empty string.

Return Value

SuccessThe handle of the window.

WinActivate Example


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)

If you don't want it to exit, you can just remove the optional timeout parameter.

$hWnd = WinWait("[CLASS:SpotifyMainWindow]")