How do I stop an active AutoHotkey script?

前端 未结 4 1134
失恋的感觉
失恋的感觉 2021-02-01 16:43

Yesterday while debugging my AutoHotkey script, I accidentally triggered an endless loop of MouseMove and MouseClick events. Every 0.5 seconds my mouse

相关标签:
4条回答
  • 2021-02-01 17:00

    You could also make your script #SingleInstance force and watch for a "-quit" argument or something.

    #SingleInstance force
    #Persistent
    
    If A_Args[1] == "--stop"
        ExitApp
    
    ; just some random stuff for the script to do
    count := 0
    Loop,
    {
        count++
        Tooltip, %count%
        Sleep, 200
    }
    

    So you run the same script again but with the argument. And BAM its gone.

    Just for completeness. @Stevoisiak's answer is already great for the purpose requested.

    0 讨论(0)
  • 2021-02-01 17:04

    If you want to close a specific window without doing a loop, I have created the following:

    DetectHiddenWindows, On
    
    path = %A_Desktop%\Test.ahk - AutoHotkey v1.1.26.01
    
    path2 = %A_Desktop%\Test2.ahk - AutoHotkey v1.1.26.01
    
    WinClose, %path%
    
    WinClose, %path2%
    

    **NOTE 1 : ** the file name + " - AutoHotKey blah blah blah" (This is the window name for hot key when you open the window hidden on your bottom right corner close to the clock)

    **NOTE 2 : ** the file names have to be case sensitivity.

    0 讨论(0)
  • 2021-02-01 17:09

    Add an emergency exit hotkey

    The most reliable method of ending an active script is to pre-emptively include an emergency ExitApp hotkey. A common practice is to place the following at the bottom of any script.

    Esc::ExitApp  ; Exit script with Escape key
    

    You can also set hotkeys to pause, suspend, or reload your script.

    ^!p::Pause    ; Pause script with Ctrl+Alt+P
    ^!s::Suspend  ; Suspend script with Ctrl+Alt+S
    ^!r::Reload   ; Reload script with Ctrl+Alt+R
    

    Log off

    On Windows 10/8/7/Vista, you can quickly log off with the keyboard shortcut Ctrl+Alt+Delete, followed by Alt+L.

    This is because pressing Ctrl+Alt+Delete opens a special window which cannot be manipulated by programs like AutoHotkey.

    End with taskbar icon

    If you have control of the keyboard and mouse, you can end the script by right-clicking AutoHotkey's green H icon in the taskbar and selecting "Exit"

    End all active scripts with AHKPanic()

    For a more generic solution, AHK user None wrote AHKPanic(), a method which can pause, suspend, or kill all other running scripts. (Optionally ends the script that called it)

    AHKPanic(Kill=0, Pause=0, Suspend=0, SelfToo=0) {
    DetectHiddenWindows, On
    WinGet, IDList ,List, ahk_class AutoHotkey
    Loop %IDList%
      {
      ID:=IDList%A_Index%
      WinGetTitle, ATitle, ahk_id %ID%
      IfNotInString, ATitle, %A_ScriptFullPath%
        {
        If Suspend
          PostMessage, 0x111, 65305,,, ahk_id %ID%  ; Suspend. 
        If Pause
          PostMessage, 0x111, 65306,,, ahk_id %ID%  ; Pause.
        If Kill
          WinClose, ahk_id %ID% ;kill
        }
      }
    If SelfToo
      {
      If Suspend
        Suspend, Toggle  ; Suspend. 
      If Pause
        Pause, Toggle, 1  ; Pause.
      If Kill
        ExitApp
      }
    }
    
    0 讨论(0)
  • 2021-02-01 17:10

    If you want to get fancy and stop it from the Windows command prompt,

    Stop all autohotkey scripts with:

    taskkill /im "autohotkey.exe"
    

    Stop specific script with:

    wmic process where "commandline like '%%MyScript.ahk'" delete
    
    0 讨论(0)
提交回复
热议问题