By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt WinActivate Function

Activating windows using AutoIts WinActivate function.

Edited: 2015-01-15 22:06

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.

Parameters

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.
Failure0

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)