Jump to content

Schedule/Run script every 30 seconds


Recommended Posts

Hi,
I want to call the "ControlClick" function to click on a button . But I want to either schedule it to run every 30 seconds or in the script itself, run it every thirty seconds until a duration of 3 hours. How do I achieve it? Sorry, new to AutoIT, trying to learn. I tried something like this:

While 1
Sleep(1000 * 29)

ControlClick("Window","","[CLASS:Button; INSTANCE:1]")
WEnd

But how do I stop at the 3 hour mark?

Link to comment
Share on other sites

If you just want to keep a chat active or something.. where it doesn't need to be EXACTLY 30 seconds... What I wrote for you below is a simple way to go about it, play with it and make it your own. Good luck. If you want exactly times, used what @Jos gave you.

 

Super simple rough example: 

$counter = 0 
; 3 hours = 180minutes * 60seconds = 10800 seconds  * 2 (control clicks per minute) = 21600

While $counter <> 21600 ; Adjust as needed.
    ConsoleWrite("This loop has been completed " & $counter & " times." & @CRLF) ; Replace this with control click
    $counter = $counter + 1 ;Just a simple counter.
Sleep(30000); 30 second pause
WEnd

 

Link to comment
Share on other sites

Hello,

  a loop takes 30 seconds, 3 hours = 360 loops!

$counter = 0 
; 3 hours = 180minutes * 2 (control clicks per minute) = 360

While $counter < 360 ; Adjust as needed.
    ConsoleWrite("This loop has been completed " & $counter & " times." & @CRLF) ; Replace this with control click
    $counter = $counter + 1 ;Just a simple counter.
Sleep(30000); 30 second pause
WEnd

 

Edited by bernd670

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

Link to comment
Share on other sites

10 hours ago, BatMan22 said:

If you just want to keep a chat active or something.. where it doesn't need to be EXACTLY 30 seconds... What I wrote for you below is a simple way to go about it, play with it and make it your own. Good luck. If you want exactly times, used what @Jos gave you.

 

Super simple rough example: 

$counter = 0 
; 3 hours = 180minutes * 60seconds = 10800 seconds  * 2 (control clicks per minute) = 21600

While $counter <> 21600 ; Adjust as needed.
    ConsoleWrite("This loop has been completed " & $counter & " times." & @CRLF) ; Replace this with control click
    $counter = $counter + 1 ;Just a simple counter.
Sleep(30000); 30 second pause
WEnd

 

If your in a loop incimenting the counter by 1 each loop and you have a 30 second sleep in the loop your counter is only going up by 1 every 30 seconds.

So it would take 21600*30 seconds to exit that loop approximately, aka like a week :)

Link to comment
Share on other sites

I personally like to use AdLibRegister() when I need things to repeat or be time based.

https://www.autoitscript.com/autoit3/docs/functions/AdlibRegister.htm

Normally it's used for things to repeat over and over in a small time window, but I see no reason it can not be used for long duration's as well.

So you can get a pretty easy to built, read, and modify script with framework like this:

AdlibRegister("_Terminate", 1000*60*60*3) ;3  Hours
AdlibRegister("_KeepAlive", 1000*30) ;30 Seconds

While 1
    Sleep(10)
WEnd

Func _Terminate()
    Exit
EndFunc

Func _KeepAlive()
    ;If WinExists or If ProcessExists Then
        ;ControlClick()
    ;Else
        ;_Terminate()
    ;EndIf
EndFunc

 

Link to comment
Share on other sites

11 hours ago, ViciousXUSMC said:

If your in a loop incimenting the counter by 1 each loop and you have a 30 second sleep in the loop your counter is only going up by 1 every 30 seconds.

So it would take 21600*30 seconds to exit that loop approximately, aka like a week :)

 Ooops. Well I TOLD him to adjust the numbers :)  #mathishard

Link to comment
Share on other sites

11 hours ago, bernd670 said:

Hello,

  a loop takes 30 seconds, 3 hours = 360 loops!

$counter = 0 
; 3 hours = 180minutes * 2 (control clicks per minute) = 360

While $counter < 360 ; Adjust as needed.
    ConsoleWrite("This loop has been completed " & $counter & " times." & @CRLF) ; Replace this with control click
    $counter = $counter + 1 ;Just a simple counter.
Sleep(30000); 30 second pause
WEnd

 

2100 and 360 are almost the same. 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...