'How do I stop an active AutoHotkey script?
Yesterday while debugging my AutoHotkey script, I accidentally triggered an endless loop of MouseMove and MouseClick events. Every 0.5 seconds my mouse would click random parts of the screen.
After unsuccessfully trying to terminate AHK with the task manager, I ended up turning off my computer to end the script.
How can I stop an active AutoHotkey script?
Solution 1:[1]
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
Solution 2:[2]
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.
Solution 3:[3]
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.?
Solution 4:[4]
I was also looking for how to close one specific running script from another autohotkey script, so I tried cristivaldo's solution but it wasn't quite working for me, so I changed it a bit.
I added SetTitleMatchMode, 2 so it matches window titles with partial matches, so you don't have to type exactly the full window title (that way it will still match even if the autohotkey version number changes). I also removed the path, and variables.
Here's an example to stop/close a specific script (just change examplescriptfile.ahk to the filename of the running autohotkey script you wish to stop):
DetectHiddenWindows, On
SetTitleMatchMode, 2
WinClose, examplescriptfile.ahk
Solution 5:[5]
1.go to the windows tray
2.right-click on the "H" sign
3.click on "suspend hotkeys" or "exit"
This is the easiest and the most simplest way to stop autohotkey scripts
but dont click on pause script, otherwise remapped keys will be shutdown
also, if you have suspended the hotkeys, the "H" will become a "S"
Hope this helped.
Solution 6:[6]
I think you can also do CTRL+ALT+DEL
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PBeezy |
| Solution 2 | LuFFy |
| Solution 3 | |
| Solution 4 | gamingexpert13 |
| Solution 5 | Anonymous |
| Solution 6 | mbourd |
