如何停止活动的 AutoHotkey 脚本? [英] How do I stop an active AutoHotkey script?
问题描述
昨天在调试我的 AutoHotkey 脚本时,我不小心触发了 MouseMove
和 MouseClick
事件的无限循环.每 0.5 秒我的鼠标就会点击屏幕的随机部分.
在尝试使用任务管理器终止 AHK 失败后,我最终关闭了计算机以结束脚本.
如何停止活动的 AutoHotkey 脚本?
添加紧急出口热键
结束活动脚本最可靠的方法是预先包含紧急情况
使用 AHKPanic() 结束所有活动脚本
对于更通用的解决方案,AHK 用户 None 写了 AHKPanic()
,一种可以暂停、挂起或终止所有其他正在运行的脚本的方法.(可选地结束调用它的脚本)
AHKPanic(Kill=0, Pause=0, Suspend=0, SelfToo=0) {检测隐藏的Windows,打开WinGet, IDList ,List, ahk_class AutoHotkey循环 %IDList%{ID:=IDList%A_Index%WinGetTitle, ATitle, ahk_id %ID%IfNotInString, ATitle, %A_ScriptFullPath%{如果暂停PostMessage, 0x111, 65305,,, ahk_id %ID% ;暂停.如果暂停PostMessage, 0x111, 65306,,, ahk_id %ID% ;暂停.如果杀WinClose, ahk_id %ID% ;kill}}如果自己也是{如果暂停暂停,切换;暂停.如果暂停暂停,切换,1;暂停.如果杀退出应用}}
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?
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
}
}
这篇关于如何停止活动的 AutoHotkey 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!