Pause a timer loop without pausing the whole script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Batsmaru0410
Posts: 12
Joined: 19 Jan 2019, 12:25

Pause a timer loop without pausing the whole script

04 Apr 2020, 02:58

I have assigned a key to a perform a timer loop, that cycles through my Notepad, explorer and Powerpoint windows every 4 seconds.

I hit the assigned toggle key again to pause. But the problem is that I have to wait for the function "Hit 4" to terminate before it completely stops.

Is there a way to pause the function immediately after a keystroke, without having to wait for the whole "Hit 4" to finish? I don't want to pause the whole script, just this function.

Thanks


Code: Select all

NumpadEnter::

		 	
 	if (HitToggle4 := !HitToggle4){
		SetTimer, Hit4, 12250	
		GoSub, Hit4	
	} else {
		SetTimer, Hit4, Off
	}
  	return
  
Hit4:
	WinActivate, NotePad
	sleep 4000
	WinActivate, Exploer
	sleep 4000
	WinActivate, PowerPoint
	sleep 4000

	return
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pause a timer loop without pausing the whole script

04 Apr 2020, 04:25

Give this a try

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
Arr:=["NotePad","Exploer","PowerPoint"]
Index := 1
return

NumpadEnter::
 	if (HitToggle4 := !HitToggle4){
		SetTimer, Hit4, 4000
		GoSub, Hit4	
	} else {
		SetTimer, Hit4, Off
	}
  	return
  
Hit4:
	WinActivate,% (Index>Arr.Length())?(Arr[Index:=1]):(Arr[Index++])
	return


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot], terraformars and 261 guests