How to toggle off and on a loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CallMeSeby
Posts: 8
Joined: 23 Jun 2017, 14:45

How to toggle off and on a loop

24 Jun 2017, 03:02

Code: Select all

^s::
Loop
{
	Send, {!}flipcoin 25 ;i want to be toggled off and on and btw 12000 at sleep means 2 minutes ?
	Sleep 12000
}
return
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to toggle off and on a loop

24 Jun 2017, 03:22

Hallo,
try:

Code: Select all

#MaxThreadsPerHotkey, 2
^s::
Toggle := !Toggle
While, Toggle
{
	Send, {!}flipcoin 25 ;i want to be toggled off and on and btw 12000 at sleep means 2 minutes ?
	Sleep 12000
}
return
CallMeSeby
Posts: 8
Joined: 23 Jun 2017, 14:45

Re: How to toggle off and on a loop

24 Jun 2017, 03:27

but 12000 in sleep is 2 minutes ?
CallMeSeby
Posts: 8
Joined: 23 Jun 2017, 14:45

Re: How to toggle off and on a loop

24 Jun 2017, 03:31

I'm sorry but it does not work...I press once ^s it starts then i press ^s again it continues...What i want is when i press ^s again to stop looping
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to toggle off and on a loop

24 Jun 2017, 09:07

Hallo,
better?

Code: Select all

#MaxThreadsPerHotkey, 2
^s::
flipcoin := !flipcoin
If !flipcoin
{
	SetTimer ,flipcoin, Off
	Return
}
Else
	SetTimer ,flipcoin, 120000 ;2 minutes
flipcoin:
	Send, {!}flipcoin 25
Return
CallMeSeby
Posts: 8
Joined: 23 Jun 2017, 14:45

Re: How to toggle off and on a loop

24 Jun 2017, 12:43

Code: Select all

#MaxThreadsPerHotkey 2

$x::
    Toggle := !Toggle
    while Toggle
    {
		
       Send, {!}flipcoin 25
	Send {Enter down}
	sleep 10
	Send {Enter up}
	Sleep 60000
	Send, Sal
	Send {Enter down}
	sleep 10
	Send {Enter up}
	Sleep 125000
	
    }
return
Can somebody correct this (this cant be turned off i want to toggle it with ^s on and ^s off. Whats wrong with this ? btw tell me why you modified and one more thing dont change anything thats in the loop { } (the send and sleep) you can add what you want, also dont delete anything.I want you to be noob friendly :D
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to toggle off and on a loop

26 Jun 2017, 02:40

Hallo,
long-lasting Sleeps are a problem in AutoHotkey. They can not be easily interrupted.
That's why I converted them into sequences of one-second-sleeps.

Code: Select all

#MaxThreadsPerHotkey 2
^s::
Toggle := !Toggle
while Toggle
{		
	Send, {!}flipcoin 25
	Send {Enter down}
	sleep 10
	Send {Enter up}
	Loop, 60 ;interruptible Sleep 60000
		If Toggle
			Sleep, 1000
		Else
			Return
	Send, Sal
	Send {Enter down}
	sleep 10
	Send {Enter up}
	Loop, 125 ;interruptible Sleep 125000
		If Toggle
			Sleep, 1000
		Else
			Return
}
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot] and 107 guests