如何停止活动的AutoHotkey脚本? [英] How do I stop an active AutoHotkey script?

查看:3008
本文介绍了如何停止活动的AutoHotkey脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天调试我的AutoHotkey脚本时,我意外地触发了MouseMoveMouseClick事件的无限循环.我的鼠标每0.5秒就会点击屏幕的随机部分.

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.

在尝试用任务管理器终止AHK失败后,我最终关闭了计算机以结束脚本.

After unsuccessfully trying to terminate AHK with the task manager, I ended up turning off my computer to end the script.

如何停止活动的AutoHotkey脚本?

推荐答案

添加紧急出口热键

结束活动脚本的最可靠方法是抢先包含紧急情况 ExitApp 热键.一种常见的做法是将以下内容放在任何脚本的底部.

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

注销

在Windows 10/8/7/Vista上,您可以使用键盘快捷键 Ctrl + Alt + Delete 快速注销按 Alt + L .

Log off

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

这是因为按Ctrl + Alt + Delete会打开一个特殊的窗口,该窗口无法由诸如AutoHotkey之类的程序操纵.

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

如果您拥有键盘和鼠标的控制权,则可以通过右键单击任务栏中的AutoHotkey的绿色H图标并选择退出"来结束脚本.

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"

对于更通用的解决方案,AHK用户无人编写 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆