Need help with pauseing a looping script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Saanage
Posts: 3
Joined: 31 Jan 2019, 20:47

Need help with pauseing a looping script

31 Jan 2019, 20:57

Hey guys, need some help.
I have a script that needs to Send 1,2,3,4 in a loop with a 10 second delay between each. I have also given 5 seconds before it actually starts. I also need to be able to Toggle pausing the loop
Here is what I have so far:

#p::Pause, toggle


Sleep, 5000
Loop
{
SetKeyDelay, 10000,
Send, 1
Send, 2
Send, 3
Send, 4
}
Return


the problem is if I remove the pause function (#p::Pause, toggle) the script will keep looping and still type out the 1234 repeatedly but when I add in the pause function the script doesn't do anything. I can see in the system tray that it is running and I can Pause and unpause it easily but nothing is typed out. any help would be appreciated
wryyymuda
Posts: 31
Joined: 21 Sep 2018, 21:43

Re: Need help with pauseing a looping script

31 Jan 2019, 21:07

Code: Select all

sleep, 5000
loop {
	loop, 4 {
	send, %A_index%
	}
	sleep, 10000
	}
p::
	pause
	return
press p to pause, is toggle a built in function? if not then thats the problem.
Saanage
Posts: 3
Joined: 31 Jan 2019, 20:47

Re: Need help with pauseing a looping script

31 Jan 2019, 21:41

wryyymuda wrote:
31 Jan 2019, 21:07

Code: Select all

sleep, 5000
loop {
	loop, 4 {
	send, %A_index%
	}
	sleep, 10000
	}
p::
	pause
	return
press p to pause, is toggle a built in function? if not then thats the problem.
thanks, but this will type 1234 all at once, where as I need a gap between each number of about 10 seconds and I need to be able to pause it at any moment. Toggle is a built in function but it isn't necessary as pause defaults to toggle. with my original script above it does toggle on and off regardless of whether I have toggle written in or not.

I tried to modify your script to this

Code: Select all

sleep, 5000
loop {
	loop, 1 {
          SetKeyDelay, 1000
	  Send, 1
          Send, 2
          Send, 3
          Send, 4
	}
	sleep, 10000
	}
p::
	pause
	return
and I can pause it which is an improvement, but it will finish the cycle of 1234 before it pauses but I may need it to pause at any number.
User avatar
Cuadrix
Posts: 199
Joined: 07 May 2017, 08:26

Re: Need help with pauseing a looping script  Topic is solved

31 Jan 2019, 21:55

Look at this topic.
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=45616&p=206143
I don't think there is any other way to break out of the loop like you want it to.
----
Saanage
Posts: 3
Joined: 31 Jan 2019, 20:47

Re: Need help with pauseing a looping script

31 Jan 2019, 22:17

Cuadrix wrote:
31 Jan 2019, 21:55
Look at this topic.
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=45616&p=206143
I don't think there is any other way to break out of the loop like you want it to.
Thanks, it is basically to cycle through cameras and just stop when I need it to so this worked well for me thanks
SOTE
Posts: 716
Joined: 15 Jun 2015, 06:21

Re: Need help with pauseing a looping script

31 Jan 2019, 23:42

Saanage wrote:
31 Jan 2019, 22:17
Cuadrix wrote:
31 Jan 2019, 21:55
Look at this topic.
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=45616&p=206143
I don't think there is any other way to break out of the loop like you want it to.
Thanks, it is basically to cycle through cameras and just stop when I need it to so this worked well for me thanks
Why not put the gap of 10 seconds between each send?

Partial code

Code: Select all

Send, 1
Sleep, 10000  ; 10 seconds
Send, 2
Sleep, 10000
Send, 3
Sleep, 10000
Send, 4
Sleep, 10000
You might also want to look into and experiment with the following:

WinExist() / IfWin[Not]Exist
https://autohotkey.com/docs/commands/WinExist.htm
WinActivate
https://autohotkey.com/docs/commands/WinActivate.htm
ControlSend
https://autohotkey.com/docs/commands/ControlSend.htm

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], fiendhunter, Google [Bot] and 198 guests