iconabhi113 Posted April 16, 2018 Posted April 16, 2018 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?
Developers Jos Posted April 16, 2018 Developers Posted April 16, 2018 Look at TimerInit() & TimerDiff() functions to calculate duration. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
BatMan22 Posted April 17, 2018 Posted April 17, 2018 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
iconabhi113 Posted April 17, 2018 Author Posted April 17, 2018 Thank you @BatMan22 & @Jos. I'll try what you guys suggested.
bernd670 Posted April 17, 2018 Posted April 17, 2018 (edited) 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 April 17, 2018 by bernd670 greetingsbernd I hacked 127.0.0.1 ->
ViciousXUSMC Posted April 17, 2018 Posted April 17, 2018 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
ViciousXUSMC Posted April 17, 2018 Posted April 17, 2018 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 SkysLastChance and masvil 1 1
iconabhi113 Posted April 17, 2018 Author Posted April 17, 2018 Thanks all for the replies.. really helpful information!
BatMan22 Posted April 18, 2018 Posted April 18, 2018 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
BatMan22 Posted April 18, 2018 Posted April 18, 2018 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now