驱动级输入接管 AALC 任务流的鼠标点击(LCP_DRIVER_INPUT=1 开关)
按"应该在输入层接管"的思路做的: 不是只改 lc_mcp 自己的 click, 而是把 AALC 任务流里
所有鼠标点击都转到罗技驱动上 —— 这样镜牢/日常的点击也走物理输入。
一、lc_mcp/driver_input.py(新)
DriverInput 封装 logitech.driver.dll(device_open/moveR/mouse_down/mouse_up)。
定位用**闭环**: 发相对位移 -> 读回实际坐标 -> 不够再发, 收敛到 <=1px 才认。
不依赖任何标定常数, 也不怕偶发坐标跳变。
preflight() 有三条硬性拒绝, 每条都对应一个实测过的失败条件:
* device_open() != 1 -> 罗技驱动没就绪
* GetForegroundWindow() == 0 -> 当前不是物理交互会话(RDP 独立会话里驱动级无效;
实测那时 22 次采样光标纹丝不动, 切到 console 立刻正常)
* 指针加速开着 -> counts 与像素不成比例(实测 +100/+200/+400 对应
-45/-3/-3 像素), 关掉后严格 1:1
二、aalc_patches.py: DriverClickProxy + install_driver_click
只接管 mouse_click / mouse_down / mouse_up, 其余(拖拽/滑动/滚轮/等待)一律透传。
拖拽类不接管: 那些行为差异大, 用相对位移复现更容易出错。
⛔ 关键细节: automation.py 初始化时把方法绑成了别名
(self.mouse_click = self.input_handler.mouse_click), 所以**换 handler 不够**,
必须把别名一起重绑, 否则任务流里调的还是老方法。测试里专门守这一条。
条件不满足时**一个都不改** —— 宁可继续用原来的注入方式, 也不要半吊子接管。
三、aalc_task.py: 环境变量 LCP_DRIVER_INPUT=1 时才安装; 默认关闭。
验证(真机, 物理 console 会话):
preflight: True | ok 前台窗口存在 True 指针加速 False
move_to (400,300) / (1200,700) / (800,500) -> 误差全部 (0,0)
click(600,400) -> True
测试 15 个, 重点在"各种条件不满足时必须拒绝"。全套 399/399 通过。
This commit is contained in:
@@ -94,3 +94,85 @@ class WindowGuard(threading.Thread):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.stopped.set()
|
self.stopped.set()
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------- 驱动级点击接管
|
||||||
|
|
||||||
|
# AALC 的 automation.py 在初始化时把这些名字绑成了别名
|
||||||
|
# (self.mouse_click = self.input_handler.mouse_click 之类), 所以换掉 input_handler
|
||||||
|
# 还不够, 必须把别名一起重绑, 否则任务流里调的还是老方法。
|
||||||
|
REBIND_NAMES = ('mouse_click', 'mouse_down', 'mouse_up')
|
||||||
|
|
||||||
|
|
||||||
|
class DriverClickProxy:
|
||||||
|
"""把鼠标点击转发到罗技驱动, 其余一律透传给原 handler。
|
||||||
|
|
||||||
|
⛔ 只接管**点击类**操作。拖拽/滑动/滚轮仍走 AALC 原逻辑 —— 那些在镜牢和日常
|
||||||
|
里用得少, 而各自的行为差异(惯性、多点)不好用相对位移复现, 接了反而更容易出错。
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, handler, driver, screen, log=print):
|
||||||
|
self._handler = handler
|
||||||
|
self._driver = driver
|
||||||
|
self._screen = screen
|
||||||
|
self.log = log
|
||||||
|
self.clicks = 0
|
||||||
|
self.refused = 0
|
||||||
|
|
||||||
|
# --- 透传 -------------------------------------------------------------
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return getattr(self._handler, name)
|
||||||
|
|
||||||
|
# --- 接管 -------------------------------------------------------------
|
||||||
|
def _screen_pos(self, x, y):
|
||||||
|
from .driver_input import client_to_screen
|
||||||
|
hwnd = self._screen.handle.hwnd
|
||||||
|
return client_to_screen(hwnd, x, y)
|
||||||
|
|
||||||
|
def mouse_click(self, x, y, times=1, *args, **kwargs):
|
||||||
|
sx, sy = self._screen_pos(x, y)
|
||||||
|
if self._driver.click(sx, sy, times=times):
|
||||||
|
self.clicks += 1
|
||||||
|
self.log('[driver] 点击客户区(%d,%d) -> 屏幕(%d,%d)' % (x, y, sx, sy))
|
||||||
|
self._handler.wait_pause()
|
||||||
|
return True
|
||||||
|
self.refused += 1
|
||||||
|
self.log('[driver] 放弃点击客户区(%d,%d): 无法精确定位' % (x, y))
|
||||||
|
return False
|
||||||
|
|
||||||
|
def mouse_down(self, x=None, y=None, *args, **kwargs):
|
||||||
|
if x is not None and y is not None:
|
||||||
|
sx, sy = self._screen_pos(x, y)
|
||||||
|
if not self._driver.move_to(sx, sy):
|
||||||
|
return False
|
||||||
|
self._driver.down(1)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def mouse_up(self, x=None, y=None, *args, **kwargs):
|
||||||
|
if x is not None and y is not None:
|
||||||
|
sx, sy = self._screen_pos(x, y)
|
||||||
|
self._driver.move_to(sx, sy)
|
||||||
|
self._driver.up(1)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def install_driver_click(auto, screen, driver=None, log=print):
|
||||||
|
"""如果环境满足, 把 AALC 的鼠标点击切到罗技驱动级输入。
|
||||||
|
|
||||||
|
返回驱动实例(成功) 或 None(条件不满足, AALC 保持原样)。
|
||||||
|
条件不满足时**不改任何东西** —— 宁可继续用原来的注入方式, 也不要半吊子接管。
|
||||||
|
"""
|
||||||
|
from .driver_input import DriverInput
|
||||||
|
|
||||||
|
drv = driver or DriverInput(log=log)
|
||||||
|
ok, why = drv.preflight()
|
||||||
|
if not ok:
|
||||||
|
log('[lc_mcp] 驱动级输入未启用: %s' % why)
|
||||||
|
return None
|
||||||
|
|
||||||
|
proxy = DriverClickProxy(auto.input_handler, drv, screen, log=log)
|
||||||
|
auto.input_handler = proxy
|
||||||
|
for name in REBIND_NAMES:
|
||||||
|
if hasattr(proxy, name):
|
||||||
|
setattr(auto, name, getattr(proxy, name))
|
||||||
|
log('[lc_mcp] patch: 鼠标点击已切到罗技驱动级输入')
|
||||||
|
return drv
|
||||||
Reference in New Issue
Block a user