Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Turn all scripts on and off



  • Please log in to reply
21 replies to this topic
Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Sorry, I am running the following script (statement removed):

; http://www.autohotke...pts-on-and-off/

#SingleInstance FORCE

WM_COMMAND := 0x111
CMD_RELOAD := 65400
CMD_EDIT := 65401
CMD_PAUSE := 65403
CMD_SUSPEND := 65404

DetectHiddenWindows, On

Process, Exist
this_pid := ErrorLevel
control_id := WinExist("ahk_class AutoHotkey ahk_pid " this_pid)

; Press Home to toggle Pause & Suspend state for all scripts.

Home::
Toggle := !Toggle
WinGet, id, list, ahk_class AutoHotkey
Loop, %id%
{
	this_id := id%A_Index%
	If (this_id <> control_id)
	{
		;If (ScriptStatus(this_id, "Paused") = !Toggle)
			;PostMessage, WM_COMMAND, CMD_PAUSE,,, ahk_id %this_id%
		If (ScriptStatus(this_id, "Suspended") = !Toggle)
			PostMessage, WM_COMMAND, CMD_SUSPEND,,, ahk_id %this_id%

	}
}
Return

ScriptStatus(script_id, cmd)
{
	SendMessage, 0x211,,,, ahk_id %script_id%  ; WM_ENTERMENULOOP
	SendMessage, 0x212,,,, ahk_id %script_id%  ; WM_EXITMENULOOP

	mainMenu := DllCall("GetMenu", "uint", script_id)
	fileMenu := DllCall("GetSubMenu", "uint", mainMenu, "int", 0)
	isPaused := DllCall("GetMenuState", "uint", fileMenu, "uint", 4, "uint", 0x400) >> 3 & 1
	isSuspended := DllCall("GetMenuState", "uint", fileMenu, "uint", 5, "uint", 0x400) >> 3 & 1
	DllCall("CloseHandle", "uint", fileMenu)
	DllCall("CloseHandle", "uint", mainMenu)
	If (cmd = "Paused")
		Return isPaused
	If (cmd = "Suspended")
		Return isSuspended
}

Running the above, I get for scripts that are already in PAUSE state:

Pause -> Suspend -> Pause (This is good)

 

But I get for scripts that are already in SUSPEND state (before the toggle action):

Suspend -> Suspend -> Normal (instead of the desired Suspend -> Suspend -> Suspend because Suspend was the initial state and is desired to remain so (in their initial state of Suspend) after the toggle (for scripts that were suspended before the toggle action).



techie108
  • Members
  • 250 posts
  • Last active: Jul 20 2019 03:19 AM
  • Joined: 05 Aug 2012

just curious - why does the script not work when i merge it with my other mini scripts in a single ahk file? anything else i should add to make it work?



Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
@Guest10: You should remove only the statement, not the post message.

@techie108: Everything before the Home:: hotkey must be placed on top of your script so it will be executed before the first return.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Thanks! IMHO, the ideal script is to perform as follows:

 

Before toggle || After 1st toggle (hitting HK) || After 2nd toggle (hitting HK):

 

N > S or P > N

S > S or P > S

P > S or P > P

 

N = Normal

S = Suspend

P = Pause



techie108
  • Members
  • 250 posts
  • Last active: Jul 20 2019 03:19 AM
  • Joined: 05 Aug 2012
@Guest10: You should remove only the statement, not the post message.

@techie108: Everything before the Home:: hotkey must be placed on top of your script so it will be executed before the first return.

 

thanks for the reply. still doesn't work even after i put the first chunk of code at the top of my script. 

 

 

 

WM_COMMAND := 0x111
CMD_RELOAD := 65400
CMD_EDIT := 65401
CMD_PAUSE := 65403
CMD_SUSPEND := 65404

DetectHiddenWindows, On

Process, Exist
this_pid := ErrorLevel
control_id := WinExist("ahk_class AutoHotkey ahk_pid " this_pid)


Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012

May I see your full script then?


Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


smyzzyx
  • Members
  • 6 posts
  • Last active: Apr 05 2013 12:05 PM
  • Joined: 29 Mar 2013

would it be possible if you just have a suspend and unsuspend button? xD thanks