The only ways to suspend or unsuspend another script are:
- By sending a menu command message; i.e. toggling.
- By implementing some form of inter-process communication (message-passing) and having the other script suspend itself.
However, what you can do is check whether a script is suspended before sending it the toggle message. You can do this by checking whether the Suspend Hotkeys menu item has a checkmark.
ScriptSuspend(ScriptName, SuspendOn)
{
; Get the HWND of the script's main window (which is usually hidden).
dhw := A_DetectHiddenWindows
DetectHiddenWindows On
if scriptHWND := WinExist(ScriptName " ahk_class AutoHotkey")
{
; This constant is defined in the AutoHotkey source code (resource.h):
static ID_FILE_SUSPEND := 65404
; Get the menu bar.
mainMenu := DllCall("GetMenu", "ptr", scriptHWND)
; Get the File menu.
fileMenu := DllCall("GetSubMenu", "ptr", mainMenu, "int", 0)
; Get the state of the menu item.
state := DllCall("GetMenuState", "ptr", fileMenu, "uint", ID_FILE_SUSPEND, "uint", 0)
; Get the checkmark flag.
isSuspended := state >> 3 & 1
; Clean up.
DllCall("CloseHandle", "ptr", fileMenu)
DllCall("CloseHandle", "ptr", mainMenu)
if (!SuspendOn != !isSuspended)
SendMessage 0x111, ID_FILE_SUSPEND,,, ahk_id %scriptHWND%
; Otherwise, it's already in the right state.
}
DetectHiddenWindows %dhw%
}
Usage is as follows:
SetTitleMatchMode 2 ; Allow filename instead of full path.
ScriptSuspend("script1.ahk", true) ; Suspend.
ScriptSuspend("script1.ahk", false) ; Unsuspend.
You can do the same for Pause by replacing ID_FILE_SUSPEND (65404) with ID_FILE_PAUSE (65403). However, you need to send the WM_ENTERMENULOOP (0x211) and WM_EXITMENULOOP (0x212) messages to the script for the Pause Script checkmark to be updated.