tjc*_*mon 5 scripting autohotkey
我有一个脚本想要监视另外 2 个脚本。基本上,如果监视器脚本看到记事本打开,它将检查 script1 是否已挂起,如果是,则不执行任何操作,如果不是,则挂起 script1 并取消挂起 script2。
If (WinExist("ahk_class Notepad") AND (script1 A_IsSuspended = 1)){
Suspend script2
un-suspend script1
}
Run Code Online (Sandbox Code Playgroud)
如何检查其他脚本是否已暂停?
有没有办法发送暂停开/关而不是切换到脚本?这是切换:PostMessage, 0x111, 65305,,, script1.ahk - AutoHotkey
暂停或取消暂停另一个脚本的唯一方法是:
但是,您可以做的是在向脚本发送切换消息之前检查脚本是否已挂起。您可以通过检查“暂停热键”菜单项是否有复选标记来执行此操作。
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%
}
Run Code Online (Sandbox Code Playgroud)
用法如下:
SetTitleMatchMode 2 ; Allow filename instead of full path.
ScriptSuspend("script1.ahk", true) ; Suspend.
ScriptSuspend("script1.ahk", false) ; Unsuspend.
Run Code Online (Sandbox Code Playgroud)
您可以通过将 ID_FILE_SUSPEND (65404) 替换为 ID_FILE_PAUSE (65403) 来对暂停执行相同的操作。但是,您需要将 WM_ENTERMENULOOP (0x211) 和 WM_EXITMENULOOP (0x212) 消息发送到脚本,以便更新“暂停脚本”复选标记。