toggle Pause - possible? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

toggle Pause - possible?

23 Apr 2021, 10:44

Suppose a program "spins on" in a loop.
When the spacebar is pressed, the program is toggle from run to pause and
next time the spacebar is pressed, the program is toggle from pause to run and so on.
Is the only way to use SetTimer?
How?
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: toggle Pause - possible?

23 Apr 2021, 10:58

Describe what you would like to happen, step by step, including an example.
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Re: toggle Pause - possible?

23 Apr 2021, 13:25

Maybe this can be a test program?

Code: Select all

#SingleInstance force
Loop 30
{	Sleep 1000
	ToolTip % "         " A_Index "`n`nPress spacebar`nto stop / start"
}

MsgBox Ready!
ExitApp

ESC::ExitApp
The first time the spacebar is pressed, the loop is paused
Next time the spacebar is pressed, the program (the loop) is run again.
(and so on)
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: toggle Pause - possible?

23 Apr 2021, 13:45

I see no such hotkey in your script.
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Re: toggle Pause - possible?

23 Apr 2021, 15:59

No - (is hotkey a problem?)
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: toggle Pause - possible?

23 Apr 2021, 16:19

I do not know whether AHK is a problem, because you have not provided a step-by-step description of what should happen. Are you just trying to create a toggle for a loop?

Code: Select all

n := 0

Space::
SetTimer, Go, % (on := !on) ? 1000 : "Off"
SoundBeep, 1000 + 500 * on
Return

Go:
ToolTip, xyz
If (++n < 30)
 Return
MsgBox Ready!
ExitApp
teadrinker
Posts: 4368
Joined: 29 Mar 2015, 09:41
Contact:

Re: toggle Pause - possible?  Topic is solved

23 Apr 2021, 17:25

Code: Select all

#SingleInstance force
Loop 30
{	Sleep 1000
	ToolTip % "         " A_Index "`n`nPress spacebar`nto stop / start"
}

MsgBox Ready!
ExitApp

Space::Pause
Something like this, maybe?
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: toggle Pause - possible?

23 Apr 2021, 18:59

That's much easier!
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Re: toggle Pause - possible?

24 Apr 2021, 05:12

Yes! :bravo: :dance:
Thank you!
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Re: toggle Pause - possible?

24 Apr 2021, 05:38

I try to do something like this

Code: Select all

Space::
	GuiControl 1:, PauseTxt, (spacebar = run again)
	Pause Toggle
Return
The program is paused but cannot be restarted with the spacebar

edit .: And I like the Beep (by @mikeyww above)
teadrinker
Posts: 4368
Joined: 29 Mar 2015, 09:41
Contact:

Re: toggle Pause - possible?

24 Apr 2021, 05:46

Code: Select all

Space::
	Pause,, 1
	SoundBeep
Return
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Re: toggle Pause - possible?

24 Apr 2021, 09:45

It became a combination of both solutions...
First I tried to use A_IsPaused to select different tones when the program is stopped or started (but did not succeed)

Code: Select all

Loop 30
{	Sleep 1000
	ToolTip % "Running .: " A_Index "`nA_IsPaused .: " A_IsPaused "`n" on
}

Space::
	Pause,, 1
	(on := !on) ? 1000 : "Off"
	SoundBeep, 1000 + 500 * on		
	ToolTip % "A_IsPaused .: " A_IsPaused "`n" on
Return
teadrinker
Posts: 4368
Joined: 29 Mar 2015, 09:41
Contact:

Re: toggle Pause - possible?

24 Apr 2021, 10:26

Code: Select all

Loop 30
{	Sleep 1000
	ToolTip % "Running .: " A_Index "`nA_IsPaused .: " A_IsPaused
}

Space::
	Pause,, 1
	SoundBeep, 1000 + 500 * A_IsPaused		
	ToolTip % "A_IsPaused .: " A_IsPaused
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Leonardo_Portela and 168 guests