? hotkey to toggle suspend & pause at the same time does not work? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
autocart
Posts: 165
Joined: 12 May 2014, 07:42

? hotkey to toggle suspend & pause at the same time does not work?

30 Apr 2020, 18:27

Hi all,
This code does not work, and I don't understand why:

Code: Select all

^t::
Suspend, Toggle
Pause, Toggle
MsgBox, test
return
It does suspend and toggle the script at first press of Ctrl+t, as can be seen looking at the tray icon.
But pressing it again, does not do anything. Why?
I thought, it should un-suspend and unpause the script.
Using only the Suspend or Pause command without the other, works as expected.
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Re: ? hotkey to toggle suspend & pause at the same time does not work?

01 May 2020, 03:24

Code: Select all

^t::
	Suspend
	Pause
return

#If (A_IsSuspended)

	^t::
		Suspend, off	
		Pause, off	
	return

#If
Rohwedder
Posts: 3231
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: ? hotkey to toggle suspend & pause at the same time does not work?

01 May 2020, 03:47

Hallo,
or just:

Code: Select all

^t::
Suspend
Pause,,1
return
autocart
Posts: 165
Joined: 12 May 2014, 07:42

Re: ? hotkey to toggle suspend & pause at the same time does not work?  Topic is solved

01 May 2020, 05:10

Ah, ok, found the reason in the help file under "Threads":
By default, a given hotkey or hotstring subroutine cannot be run a second time if it is already running. Use #MaxThreadsPerHotkey to change this behavior.
Obviously variants are considert different hotkeys in this context, which is why your script, GEV, works. :thumbup:

And with your's Rohwedder, the underlying thread it paused and the hotkey itself can finish nicely. :thumbup: Which, now that I see clearer, makes much more sense in my application. Even more, I can now see that I will probably not need Pause at all. :mrgreen:

Thx to both of you for your help!

EDIT: Since I can only mark one post as solution, I will mark my own. However, both of your's contain a solution.
autocart
Posts: 165
Joined: 12 May 2014, 07:42

Re: ? hotkey to toggle suspend & pause at the same time does not work?

01 May 2020, 05:21

P.S.:
And the reason, why

Code: Select all

^t::
Pause, Toggle
MsgBox, test
return
works, I assume, must be because AHK must have a build in logic for this special case, allowing another thread of the same hotkey (even with default settings) after all only for this case. Probably similar to what the help describes for Suspend, if it is the first line in the hotkey subroutine, although it does not explicitly say so in the description of Pause. But that is how it behaves, as far as I can see.

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, Google [Bot], mikeyww, phucnguyenphi123, SoMuchStyle and 43 guests