Sign in to follow this  
Followers 0
alex7718

Noob...simple Script Question On Looping/pausing

6 posts in this topic

Ok I am running a very simple script to do some button presses for me in an open program and infinitely loop. Here is the script I have so far:

While 1

WinActivate("Window Name", "Start")

WinWaitActive("Window Name", "Start")

ControlClick("Window Name", "Start", 1004)

WinWaitActive("Window Name", "Finished")

ControlClick("Window Name", "Finished", 1007)

WinWaitActive("Window Name", "Exit")

ControlClick("Window Name", "Exit", 1145)

Wend

The script above works for me great, but I would like to add a 60 second pause (sleep) after the 4th line. Should be pretty simple with a "Sleep" function but here is where it gets too tricky for my noob brain to handle; I would like it to pause for 60 seconds and check if a window exists yet and if not then go back to sleep for another 60 seconds and try again in a continous loop. Once the window is finally present then I would like to to resume the rest of the commands. Here is a visual example of what I mean:

While 1

WinActivate("Window Name", "Start")

WinWaitActive("Window Name", "Start")

ControlClick("Window Name", "Start", 1004)

*****PAUSE SCRIPT FOR 60 SECONDS THEN CHECK TO SEE IF WINDOW ("Window Name", "Finished")

*****EXISTS YET... IF IT DOES EXIST THEN RESUME THE SCRIPT AS INSTRUCTED BELOW... IF NOT GO

*****BACK TO SLEEP FOR ANOTHER 60 SECONDS AND TRY AGAIN IN INFINITE LOOP

WinWaitActive("Window Name", "Finished")

ControlClick("Window Name", "Finished", 1007)

WinWaitActive("Window Name", "Exit")

ControlClick("Window Name", "Exit", 1145)

Wend

I do not simply want to have a WinWaitActive command there because the program I am running is VERY intensive and I don't want the script eating up any processor/ram juice, (however small), waiting for a window. I want the script fully paused and only activating itself for a second to see the if the program is done every once in a while.

Thanks so much for anyone that can help!

Share this post


Link to post
Share on other sites



Give this a try

While 1
    If WinExists("Window Name", "Start") Then
        ControlClick("Window Name", "Start", 1004)
        Do
            Sleep(60000)
        Until WinExists("Window Name", "Finished")
        ControlClick("Window Name", "Finished", 1007)
        WinWait("Window Name", "Exit")
        ControlClick("Window Name", "Exit", 1145)
    EndIf
    Sleep(1000)
WEnd

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Welcom to the Forums!

Plz use code tags when you post codes :)

AnyWhoo, try using "WinExists" like this

If WinExists("Window Name", "Start") Then
WinActivate("Window Name", "Start")
ControlClick("Window Name", "Start", 1004)
EndIf

While 1
$on = 0
Sleep(60000);<<<60 second pause
$on = 1
Sleep(2000);<<<2 Second pause
Wend

While $on = 1
While 1
If WinExists("Window Name", "Finished") then
ControlClick("Window Name", "Finished", 1007)
EndIf

If WinExists("Window Name", "Exit")
ControlClick("Window Name", "Exit", 1145)
EndIf
Wend
Wend

EDIT:

DARN

Too Slow...MHz :(

Edited by Paulie

Share this post


Link to post
Share on other sites

THANKS SO MUCH TO BOTH YOU GUYS! I used a combination of both your suggestions and it works like a dream.......

OK..now just one more question.....I don't think I want my entire script infinitely looping anymore. How do I make it so that everything continues to loop until a window ("Window Name", "Start") no longer exists? And maybe pop a message at the end like MsgBox(64, "Terminating Script", "ALL DONE!!!")

Share this post


Link to post
Share on other sites

THANKS SO MUCH TO BOTH YOU GUYS! I used a combination of both your suggestions and it works like a dream.......

OK..now just one more question.....I don't think I want my entire script infinitely looping anymore. How do I make it so that everything continues to loop until a window ("Window Name", "Start") no longer exists? And maybe pop a message at the end like MsgBox(64, "Terminating Script", "ALL DONE!!!")

While 1
If Not WinExists("Window Name", "Start") then
MsgBox(64, "Terminating Script", "ALL DONE!!!")
Exit 0
EndIf
Wend

Share this post


Link to post
Share on other sites

You guys rule and so does AutoIt!...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0