Check if Script is paused in AutoHotkey

I have one script that I want to control 2 more scripts. Basically, if the script monitor sees notepad open, it checks to see if script1 is suspended, if it does nothing, if it doesn't suspend script1 and doesn't suspend script2.

       If (WinExist("ahk_class Notepad") AND (script1 A_IsSuspended = 1)){
            Suspend script2
            un-suspend script1
       }

      

How can I check if other scripts are suspended?

Is there a way to send suspend on / off instead of switching to script? This toggles: PostMessage, 0x111, 65305 ,, script1.ahk - AutoHotkey

+3


source to share


1 answer


The only ways to pause or abandon another script are:

  • By sending a message to a menu command; those. switching.
  • Implementing some form of interprocess communication (messaging) and including another script.

However, what you can do is check if the script is suspended before sending it a switch message. You can do this by checking the box in the Pause Hotkeys menu item.

ScriptSuspend(ScriptName, SuspendOn)
{
    ; Get the HWND of the script 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 already in the right state.
    }
    DetectHiddenWindows %dhw%
}

      



Usage looks like this:

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 WM_ENTERMENULOOP (0x211) and WM_EXITMENULOOP (0x212) messages to the script checkbox for the script pattern.

+2


source







All Articles