加急停热键 F12(驱动级点击期间用户没法用鼠标停止)

Browse Source
用户提问: "你执行脚本的时候我鼠标没法动,我怎么停止呢"

这不是小问题 —— 驱动级点击是闭环定位的: 手一动, 下一次点击前会读到新位置算出
偏差, 再把你推回目标点。所以任务跑起来时鼠标是"拔河"状态, 用户根本没法用鼠标
去点停止按钮。而 AALC 自带的 pause_hotkey 只在 GUI(app/farming_interface.py)
里注册, lc_mcp 走命令行子进程, 那条路径上没有热键监听 —— 等于跑任务时没有急停手段。

   唯一可靠的中断通道是键盘, 所以做成全局热键。

实现: lc_mcp/killswitch.py, pynput 的 GlobalHotKeys 监听, 默认 F12
(环境变量 LCP_KILL_KEY 可改)。按下后 os._exit(130) —— 任务本来就是子进程,
硬退出不留锁和半截状态, 这与 aalc_task.py "停止 = 杀进程树" 的设计一致。

装在 aalc_task.py 的 preflight 之前(尽早), 装不上只记日志不抛异常, 并明确提示
改用 Ctrl+Alt+Del —— 急停装不上不该让任务起不来, 但必须告诉用户应急手段。

验证: 13 个测试通过(键名归一化 / pynput 缺失时给应急手段 / 只触发一次 /
不重复退出 / 环境变量覆盖), 真机注册与停止均正常。全套 412 通过。
This commit is contained in:
Codex Agent
2026-10-22 15:18:11 +08:00
parent 46b5af01cd
commit 8a9495b185
3 changed files with 213 additions and 0 deletions
+5
View File
@@ -11,6 +11,7 @@ import sys
from . import preflight from . import preflight
from .aalc_engine import bootstrap from .aalc_engine import bootstrap
from . import killswitch
from .aalc_patches import (WindowGuard, driver_click_tasks, install_exact_team_match, from .aalc_patches import (WindowGuard, driver_click_tasks, install_exact_team_match,
install_robust_set_foreground) install_robust_set_foreground)
@@ -75,6 +76,10 @@ def run(task, params):
from tasks.battle import battle from tasks.battle import battle
from utils.path_manager import path_manager from utils.path_manager import path_manager
# 急停热键: 装得越早越好。驱动级点击期间鼠标被人和程序抢来抢去,
# 用户没法用鼠标点停止按钮, 键盘是唯一可靠的中断手段。
kill_listener = killswitch.install(log=log)
problems = preflight.check(preflight.collect(cfg), task, problems = preflight.check(preflight.collect(cfg), task,
desktop=None if cfg.simulator else preflight.desktop_size()) desktop=None if cfg.simulator else preflight.desktop_size())
if problems: if problems: