Please help with adding timer for pause/resume Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
KumaKun
Posts: 4
Joined: 19 Oct 2017, 01:35

Please help with adding timer for pause/resume

19 Oct 2017, 01:49

Hi, I am having trouble figuring out how to add a timer in my script to pause after a certain time and resume after a delay. I want the script to run for 20-30 mins then pause for 10-20 seconds before resuming and then repeat. Thank you very much for helping me. Here is my current script, I am not sure if the pause/resume should be coded before the toggle or after, or do I have to add any loop in it.

Code: Select all

toggle = 0
#MaxThreadsPerHotkey 2

F8::
    Toggle := !Toggle
     While Toggle{
	CoordMode, Screen
        Random, RandomT, 300, 600
	Random, RandomX, 800, 1100
	Random, RandomY, 400, 700
	Click, %RandomX%, %RandomY%
	sleep, %RandomT%
    }

return
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Please help with adding timer for pause/resume

19 Oct 2017, 02:15

Code: Select all

#NoEnv
#SingleInstance Force
#MaxThreadsPerHotkey 2
CoordMode, Mouse, Screen                            ; CoordMode, ToolTip|Pixel|Mouse|Caret|Menu [, Screen|Window|Client]
toggle := 0


F8::
	Toggle := !Toggle , starttime := A_TickCount
	While Toggle{
        Random, RandomT, 300, 600
	    Random, RandomX, 800, 1100
	    Random, RandomY, 400, 700
	    Click, %RandomX%, %RandomY%
	    sleep, %RandomT%                           ;         msec*sec*min=msec
		if ((A_TickCount-starttime) >= 1200000)    ; 10min = 1000*60*10 = 600000 | 20min = 1000*60*20 = 1200000
		{
		    Sleep 20000                            ; delay 20sec
			starttime := A_TickCount               ; reset start time
		}
    }
return
HTH

edit: fixed typo
KumaKun
Posts: 4
Joined: 19 Oct 2017, 01:35

Re: Please help with adding timer for pause/resume

19 Oct 2017, 02:46

the coding was more complicated than I thought, it is working, but I actually would like the startime to be random between 20-30mins and pause time between 10-20secs. I tried the same method I used, but the script runs once then stopped.

Code: Select all

#NoEnv
#SingleInstance Force
#MaxThreadsPerHotkey 2
CoordMode, Mouse, Screen                            ; CoordMode, ToolTip|Pixel|Mouse|Caret|Menu [, Screen|Window|Client]
toggle := 0


F8::
	Toggle := !Toggle , starttime := A_TickCount
	While Toggle{
        Random, RandomT, 300, 600
	Random, RandomX, 800, 1100
	Random, RandomY, 400, 700
	Random, RandomA, 1200000, 1800000
	Random, RandomB, 10000, 20000
	Click, %RandomX%, %RandomY%
	sleep, %RandomT%                           ;         msec*sec*min=msec
		if ((A_TickCount-starttime) >= %RandomA%)    ; 10min = 1000*60*10 = 600000 | 20min = 1000*60*20 = 1200000
		{
			Sleep %RandomB%                            ; delay 20sec
			starttime := A_TickCount               ; reset start time
		}
    }
return
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Please help with adding timer for pause/resume  Topic is solved

19 Oct 2017, 11:17

Code: Select all

#NoEnv
#SingleInstance Force
#MaxThreadsPerHotkey 2
CoordMode, Mouse, Screen                            ; CoordMode, ToolTip|Pixel|Mouse|Caret|Menu [, Screen|Window|Client]
toggle := 0


F8::
	Toggle := !Toggle , starttime := A_TickCount
	Random, RandomA, 1200000, 1800000
	While Toggle{
        Random, RandomT, 300, 600
	    Random, RandomX, 800, 1100
	    Random, RandomY, 400, 700
	    Click, %RandomX%, %RandomY%
	    sleep, %RandomT%                           ;         msec*sec*min=msec
		if ((A_TickCount-starttime) >= RandomA)    ; 10min = 1000*60*10 = 600000 | 20min = 1000*60*20 = 1200000
		{
		    Random, RandomA, 1200000, 1800000
		    Random, RandomB, 10000, 20000
			Sleep RandomB                          ; delay between 10-20sec
			starttime := A_TickCount               ; reset start time
		}
    }
return
With expression syntax RandomA does not need to be wrapped in %'s Also Sleep command allows expressions so its not needed there either but its allowed to be either way.

Give this a try you should be good to go.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Descolada, jollyjoe and 144 guests