Reputation: 115
I have a script that opens a webpage, logs in, then opens a program and is supposed to bring the program to the front and make it full screen. It opens the window but it does not always bring it to the front and it won't full screen. Can anyone offer any assistance? Here is my code:
; Closes last dialog if still open
Sleep(5000)
Send("{ENTER}")
Sleep(500)
; Wait for program to open
WinWait("[CLASS: Program example]","", 5)
;Brings Program to front
if WinExists("[CLASS: Program example]") Then
WinActivate("[CLASS: Program example]")
EndIf
Sleep(500)
; Sets program fullscreen
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
I added the WinWait to see if that would help, but it has not. The window just stays in the back and never moves. Thanks for any help provided.
Upvotes: 0
Views: 980
Reputation: 318
Sometimes AutoIt doesn't perform some task because something is happening at the same time that interfere with the command. The best way to ensure the things work is to always check if the task was performed and try again if not. This loop will solve your problem.
;Brings Program to front
While Not WinActive("[CLASS: Program example]")
WinActivate("[CLASS: Program example]")
Sleep(1000) ; Wait one second (or any seconds you want)
WEnd
Upvotes: 1