Inserting commands with a hotkey while settimer loop is ongoin

Get help with using AutoHotkey and its commands and hotkeys
Batsmaru0410
Posts: 11
Joined: 19 Jan 2019, 12:25

Inserting commands with a hotkey while settimer loop is ongoin

02 Feb 2019, 09:14

I have created a hotkey (Delete) to initiate/stop a loop of pressing spacebar and right arrow alternatively and indefinitely.

I have also created another hotkey (Insert) to do certain things that I want to do.

When I hit hotkey (Insert) while the loop is ongoing, the commands under that hotkey does not finish before the loop begins again, because the loop has an interval of 250 ms.

How do I modify the code so that when I press the hotkey, the loop will stop by itself, do and finish all the command I have under that hotkey (Insert), then continue with the loop by itself again.

Below is my code. Thank you.


Code: Select all

Delete::	
 	if (HitToggle1 := !HitToggle1){
		SetTimer, Hit1, 250	
		GoSub, Hit1		
	} else {
		SetTimer, Hit1, Off
	}
  	return
  
Hit1:
	if (IsSpace1 := !IsSpace1)
		key1 := "Space"
	else
		key1 := CurrentDir1

	ControlSend, ahk_parent, % "{" key1 "}", Fighter
  	return

Insert::

		ControlSend, ahk_parent, u, Fighter
		sleep 500
		ControlSend, ahk_parent, a, Fighter
		sleep 1500
		ControlSend, ahk_parent, {Down}, Fighter
		sleep 500
		ControlSend, ahk_parent, {Enter}, Fighter

	return
Rohwedder
Posts: 3790
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Inserting commands with a hotkey while settimer loop is ongoin

02 Feb 2019, 11:02

Hallo,
try:

Code: Select all

Insert::
	Critical
		ControlSend, ahk_parent, u, Fighter
		sleep 500
		ControlSend, ahk_parent, a, Fighter
		sleep 1500
		ControlSend, ahk_parent, {Down}, Fighter
		sleep 500
		ControlSend, ahk_parent, {Enter}, Fighter
return

Return to “Ask For Help”

Who is online

Users browsing this forum: return, songdg and 49 guests