^1::
DetectHiddenWindows, On ; Enable hidden windows detection
WinGet, List, List, ahk_class AutoHotkey ; Get a list of all running AutoHotkey scripts
Loop, % List
{
this_id := List%A_Index%
WinGetTitle, ScriptPath, ahk_id %this_id%
Splitpath, % ScriptPath, , , , ScriptPath3
SplitArray := StrSplit(ScriptPath3, ".ahk")
ScriptPath22 := SplitArray.1 ".ahk"
;MsgBox %ScriptPath22%
If ScriptPath22 = Pauser 3.ahk
{
Goto, Skip
}
SetTitleMatchMode 2 ; Allow filename instead of full path.
ScriptPause(ScriptPath22, true) ; Pause.
Skip:
}
return
^2::
DetectHiddenWindows, On ; Enable hidden windows detection
WinGet, List, List, ahk_class AutoHotkey ; Get a list of all running AutoHotkey scripts
Loop, % List
{
this_id := List%A_Index%
WinGetTitle, ScriptPath, ahk_id %this_id%
Splitpath, % ScriptPath, , , , ScriptPath3
SplitArray := StrSplit(ScriptPath3, ".ahk")
ScriptPath22 := SplitArray.1 ".ahk"
;MsgBox %ScriptPath22%
If ScriptPath22 = Pauser 3.ahk
{
Goto, Skip2
}
SetTitleMatchMode 2 ; Allow filename instead of full path.
Skip2:
}
return
; ^1::ScriptPause("test script.ahk", true) ; Pause.
; ^2::ScriptPause("test script.ahk", false) ; UnPause.
ScriptPause(ScriptName, PauseOn)
{
; 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_PAUSE := 65403
static WM_ENTERMENULOOP := 0x211
static WM_EXITMENULOOP := 0x212
; 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_PAUSE, "uint", 0)
; Get the checkmark flag.
isPaused := state >> 3 & 1
; Clean up.
DllCall("CloseHandle", "ptr", fileMenu)
DllCall("CloseHandle", "ptr", mainMenu)
if (!PauseOn != !isPaused) {
SendMessage 0x111, ID_FILE_PAUSE,,, ahk_id %scriptHWND%
SendMessage WM_ENTERMENULOOP,,,, ahk_id %scriptHWND%
SendMessage WM_EXITMENULOOP,,,, ahk_id %scriptHWND%
}
; Otherwise, it's already in the right state.
}
DetectHiddenWindows %dhw%
}