Page 1 of 1

Need help with pauseing a looping script

Posted: 31 Jan 2019, 20:57
by Saanage
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

Re: Need help with pauseing a looping script

Posted: 31 Jan 2019, 21:07
by wryyymuda

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.

Re: Need help with pauseing a looping script

Posted: 31 Jan 2019, 21:41
by Saanage
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.

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

Posted: 31 Jan 2019, 21:55
by Cuadrix
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.

Re: Need help with pauseing a looping script

Posted: 31 Jan 2019, 22:17
by Saanage
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

Re: Need help with pauseing a looping script

Posted: 31 Jan 2019, 23:42
by SOTE
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