Page 1 of 1
toggle Pause - possible?
Posted: 23 Apr 2021, 10:44
by Albireo
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?
Re: toggle Pause - possible?
Posted: 23 Apr 2021, 10:58
by mikeyww
Describe what you would like to happen, step by step, including an example.
Re: toggle Pause - possible?
Posted: 23 Apr 2021, 13:25
by Albireo
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)
Re: toggle Pause - possible?
Posted: 23 Apr 2021, 13:45
by mikeyww
I see no such hotkey in your script.
Re: toggle Pause - possible?
Posted: 23 Apr 2021, 15:59
by Albireo
No - (is hotkey a problem?)
Re: toggle Pause - possible?
Posted: 23 Apr 2021, 16:19
by mikeyww
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
Re: toggle Pause - possible? Topic is solved
Posted: 23 Apr 2021, 17:25
by teadrinker
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?
Re: toggle Pause - possible?
Posted: 23 Apr 2021, 18:59
by mikeyww
That's much easier!
Re: toggle Pause - possible?
Posted: 24 Apr 2021, 05:12
by Albireo
Yes!
Thank you!
Re: toggle Pause - possible?
Posted: 24 Apr 2021, 05:38
by Albireo
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)
Re: toggle Pause - possible?
Posted: 24 Apr 2021, 05:46
by teadrinker
Code: Select all
Space::
Pause,, 1
SoundBeep
Return
Re: toggle Pause - possible?
Posted: 24 Apr 2021, 09:45
by Albireo
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
Re: toggle Pause - possible?
Posted: 24 Apr 2021, 10:26
by teadrinker
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
Re: toggle Pause - possible?
Posted: 24 Apr 2021, 17:00
by Albireo
Thanks!