空白点击不再点桌面(回收站): 只移动光标到客户区安全点

Browse Source
- install_safe_blank_click: auto.mouse_click_blank 改成只调 mouse_to_blank, mouse_to_blank 改成
  移到客户区 (12,12) 换算出的屏幕点; LCP_BLANK_CLICK=1 还原
- 必须在 driver_click_tasks 之后再装一次: 驱动代理会把 auto.mouse_click_blank 重绑回代理,
  第一次装在被覆盖, 20 分钟里仍有 391 次 点击客户区(1,1)
- tests: test_safe_blank_click 4 例

单测: 783 passed。
This commit is contained in:
Codex Agent
2026-11-22 10:54:48 +08:00
parent 08f86dc932
commit 00babd0c78
3 changed files with 123 additions and 1 deletions
+60
View File
@@ -557,6 +557,66 @@ def _is_starlight_screen(auto):
return False
# ---------------------------------------------------------------- 空白点击(回收站)
# 2026-11-22 用户反馈"还在点回收站"。排查: 运行 20 分钟日志里有 391 次
# [driver] 点击客户区(1,1) -> 屏幕(25,50) 和 87 次 鼠标移动到空白 —— 都是 AALC 的
# mouse_click_blank()/mouse_to_blank(), 默认坐标 (1,1)。窗口一偏移/最小化, 这一点就落到
# 桌面左上角的回收站图标上(单击选中、再单击就打开)。
# 这里把"点空白"改掉: 不点, 只把光标移到游戏客户区内一个固定空点(12,12); 需要还原设 LCP_BLANK_CLICK=1。
BLANK_CLICK_ENV = 'LCP_BLANK_CLICK' # 1 = 保持 AALC 原样(点 (1,1))
BLANK_SAFE_CLIENT = (12, 12) # 客户区安全点, 换算后一定在游戏窗口内
def install_safe_blank_click(log=print, env=None):
"""「点空白」不再点桌面。返回 (原 mouse_click_blank, 原 mouse_to_blank), 未安装返回 None。"""
env = os.environ if env is None else env
if (env.get(BLANK_CLICK_ENV) or '').strip() == '1':
log('[lc_mcp] 空白点击保持 AALC 原样(%s=1)' % BLANK_CLICK_ENV)
return None
try:
from module.automation import auto
except Exception as e:
log('[lc_mcp] 空白点击补丁跳过: 无法导入 %s' % e)
return None
original_click = getattr(auto, 'mouse_click_blank', None)
original_move = getattr(auto, 'mouse_to_blank', None)
if original_click is None and original_move is None:
log('[lc_mcp] 空白点击补丁跳过: auto 没有 mouse_click_blank/mouse_to_blank')
return None
def _safe_screen_pos():
handle = getattr(getattr(auto, 'screen', None), 'handle', None)
hwnd = getattr(handle, 'hwnd', 0)
if not hwnd:
return None
try:
from .driver_input import client_to_screen
return client_to_screen(hwnd, BLANK_SAFE_CLIENT[0], BLANK_SAFE_CLIENT[1])
except OSError:
return None
def mouse_click_blank(coordinate=(1, 1), times=1, move_back=False):
# 只把光标挪进游戏内, 不再点击: 空白点击的唯一作用是别让光标挡着截图
mouse_to_blank(coordinate, move_back=move_back)
return True
def mouse_to_blank(coordinate=(1, 1), move_back=False):
pos = _safe_screen_pos()
if pos is None:
return None
if original_move is None:
return None
return original_move(pos, move_back=move_back)
if original_click is not None:
auto.mouse_click_blank = mouse_click_blank
if original_move is not None:
auto.mouse_to_blank = mouse_to_blank
log('[lc_mcp] patch: 空白点击改成只移动光标进游戏(客户区 %d,%d), 不点桌面'
% BLANK_SAFE_CLIENT)
return original_click, original_move
def install_team_screen_guard(log=print):
"""选队页守卫: 星级模板在「星之恩惠」页上的命中不算数。"""
try:
+5 -1
View File
@@ -15,7 +15,7 @@ from .aalc_patches import (TaskAbort, WindowGuard, driver_click_tasks, headless_
install_back_button_result, install_default_battle_team, install_event_choices,
install_exact_team_match, install_gift_confirm_guard, install_gift_preference,
install_image_error_guard, install_key_hold, install_progress_watchdog,
install_rabbit_hole, install_robust_set_foreground, install_shop_audit, install_shop_by_name,
install_rabbit_hole, install_robust_set_foreground, install_safe_blank_click, install_shop_audit, install_shop_by_name,
install_system_team_selection, install_team_screen_guard,
install_theme_pack_audit, install_theme_pack_refresh_click, install_theme_pack_systems,
install_typed_keyboard_road, load_rabbit_hole, mirror_progress, stop_driver_click)
@@ -157,6 +157,7 @@ def _run(task, params):
if task in ('mirror', 'all'):
install_back_button_result(log=log) # 上游 V1.6.2 拿 click_element 返回的 True 当坐标, 首次引导页 TypeError
install_system_team_selection(log=log, names=rabbit['team_names'] if rabbit else None)
install_safe_blank_click(log=log) # 「点空白」不再点桌面(回收站)
install_team_screen_guard(log=log)
install_gift_confirm_guard(log=log) # 「获得E.G.O饰品」点不关时换落点/结束任务(ISSUES I-06)
install_image_error_guard(log=log) # 截图连续识别失败即结束任务(防窗口没了还空转)
@@ -179,6 +180,9 @@ def _run(task, params):
originals = apply_overrides(cfg, task, params, restore_path)
with driver_click_tasks(scheme, auto, screen, cfg, log=log), \
mirror_progress(scheme) as progress:
# 驱动代理是这里才装的(会把 auto.mouse_click_blank 重新绑到代理上),
# 所以空白点击补丁要再装一次,否则被覆盖回「点 (1,1)」→ 点到桌面回收站。
install_safe_blank_click(log=log)
try:
if task == 'all':
with headless_hdr_warning(scheme, log=log):
+58
View File
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
"""「点空白」不再点到桌面回收站。
2026-11-22: 一轮 20 分钟里 391 次 `点击客户区(1,1)` + 87 次 `鼠标移动到空白`, 全是
mouse_click_blank()/mouse_to_blank() 的默认坐标 (1,1)。窗口一偏移这点就落到桌面左上角
回收站图标上。
"""
import sys
import types
import unittest
from pathlib import Path
from unittest import mock
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO))
from lc_mcp import aalc_patches as ap # noqa: E402
from lc_mcp import driver_input as di # noqa: E402
class SafeBlankClickTest(unittest.TestCase):
def install(self, auto, env=None):
module = types.ModuleType('module.automation')
module.auto = auto
with mock.patch.dict(sys.modules, {'module': types.ModuleType('module'),
'module.automation': module}):
return ap.install_safe_blank_click(log=lambda *_: None, env=env or {})
def make_auto(self):
auto = mock.Mock()
auto.screen.handle.hwnd = 99
auto.mouse_click_blank.return_value = True
auto.mouse_to_blank.return_value = None
return auto
def test_click_blank_only_moves_cursor(self):
auto = self.make_auto()
self.install(auto)
with mock.patch.object(di, 'client_to_screen', return_value=(25, 50)) as c2s:
self.assertTrue(auto.mouse_click_blank())
c2s.assert_called_once_with(99, *ap.BLANK_SAFE_CLIENT)
def test_move_blank_uses_client_safe_point(self):
auto = self.make_auto()
original_move = auto.mouse_to_blank
self.install(auto)
with mock.patch.object(di, 'client_to_screen', return_value=(25, 50)):
auto.mouse_to_blank()
# 传给原方法的是屏幕坐标 (25,50), 不是 (1,1)
original_move.assert_called_once_with((25, 50), move_back=False)
def test_env_one_keeps_upstream(self):
auto = self.make_auto()
self.assertIsNone(self.install(auto, env={ap.BLANK_CLICK_ENV: '1'}))
def test_missing_auto_methods_skips(self):
auto = mock.Mock(spec=[])
self.assertIsNone(self.install(auto))