修复点击时画面抽搐, 并把截屏自检改成走 AALC 实际用的采集路径
一、为什么"我用脚本点击时画面一直抽搐, AALC 点击不抽搐"
链条查清了:
* lc_mcp/aalc_engine.py 的 click 每次先 set_window_transparent(True)
* 而这个方法的实现是 SetLayeredWindowAttributes(hwnd, 0, 0, LWA_ALPHA)
—— alpha=0, 整个游戏窗口**完全透明(看不见)**
* 它原来**只有 background_screenshot 会恢复成 False**(screenshot.py:194)
* 我的脚本是"点击 -> 截图 -> 点击 -> 截图"高频交替
=> 窗口在不可见/可见之间反复切换 => 肉眼看就是一直抽搐
AALC 自己的 WindowMoveInput.mouse_click 只搬窗口、**根本不碰透明度**, 所以它最多
"跳一下", 不会闪 —— 这就是两边观感不同的原因。
改法: 透明度在**本次点击/拖动结束时立刻还原**, 并且放在嵌套 try/finally 里 ——
还原位置那步也可能抛错(任务被停), 不能让它把透明度还原跳过去, 否则窗口会一直隐形。
(第一版就是把还原排在 finally 里的 sleep 之后, 测试里"异常路径"那条立刻抓到了。)
二、render_ok() 改成测 AALC 真正走的那条路
原来只测屏幕 BitBlt(GetDC(0))。2026-10-22 实测它在 RDP 会话下会瞬时失败, 而 AALC
走的是 background_screenshot(窗口 DC + PrintWindow), 那条路照样能截到图 —— 我的自检
把本来能干活的轮次判成"截不到图"跳过了(10-17 02:23 就白丢过一轮)。
现在优先测窗口能否采集, 窗口不在或不可采才回退到屏幕。
测试: 新增 3 个(点击内还原/异常也还原/前台模式不碰透明度) + 4 个 render_ok 分支。
全套 384/384 通过。
This commit is contained in:
@@ -236,8 +236,16 @@ class AalcEngine(Engine):
|
|||||||
self.auto.wait_pause()
|
self.auto.wait_pause()
|
||||||
for _ in range(int(times)):
|
for _ in range(int(times)):
|
||||||
position = None
|
position = None
|
||||||
|
transparent = False
|
||||||
if self.cfg.win_input_type == 'window_move':
|
if self.cfg.win_input_type == 'window_move':
|
||||||
|
# 搬到光标下面时设成透明/点击穿透, 免得挡住用户的光标。
|
||||||
|
# ⛔ 必须在本次点击结束时就还原: 以前只有 background_screenshot
|
||||||
|
# 会把它恢复成 False, 于是"点击 -> 截图 -> 点击 -> 截图"这种
|
||||||
|
# 高频交替会让游戏窗口在不可见/可见之间反复切换 —— 肉眼看就是
|
||||||
|
# 画面一直抽搐。AALC 自己的 WindowMoveInput.mouse_click 根本不碰
|
||||||
|
# 透明度, 所以它只是"跳一下", 不会闪。
|
||||||
self.screen.handle.set_window_transparent(True)
|
self.screen.handle.set_window_transparent(True)
|
||||||
|
transparent = True
|
||||||
position = handler._set_window_pos(int(x), int(y))
|
position = handler._set_window_pos(int(x), int(y))
|
||||||
handler.set_active()
|
handler.set_active()
|
||||||
self._background_mouse(win32con.WM_MOUSEMOVE, x, y)
|
self._background_mouse(win32con.WM_MOUSEMOVE, x, y)
|
||||||
@@ -246,10 +254,16 @@ class AalcEngine(Engine):
|
|||||||
try:
|
try:
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
finally:
|
finally:
|
||||||
|
# 嵌套 try/finally: 还原位置那步也可能抛错(比如任务被停),
|
||||||
|
# 但透明度**无论如何**都要还原, 否则窗口会一直隐形。
|
||||||
|
try:
|
||||||
self._background_mouse(win32con.WM_LBUTTONUP, x, y)
|
self._background_mouse(win32con.WM_LBUTTONUP, x, y)
|
||||||
if position is not None:
|
if position is not None:
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
self._restore_background_position(position)
|
self._restore_background_position(position)
|
||||||
|
finally:
|
||||||
|
if transparent:
|
||||||
|
self.screen.handle.set_window_transparent(False)
|
||||||
# Let Unity consume the release before another target is selected.
|
# Let Unity consume the release before another target is selected.
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
elif not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
elif not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
||||||
@@ -305,8 +319,11 @@ class AalcEngine(Engine):
|
|||||||
import win32con
|
import win32con
|
||||||
self.auto.wait_pause()
|
self.auto.wait_pause()
|
||||||
position = None
|
position = None
|
||||||
|
transparent = False
|
||||||
if self.cfg.win_input_type == 'window_move':
|
if self.cfg.win_input_type == 'window_move':
|
||||||
|
# 同 click(): 透明必须在本次拖动结束时就还原, 不能留给下一次截图
|
||||||
self.screen.handle.set_window_transparent(True)
|
self.screen.handle.set_window_transparent(True)
|
||||||
|
transparent = True
|
||||||
position = self.auto.input_handler._set_window_pos(int(from_x), int(from_y))
|
position = self.auto.input_handler._set_window_pos(int(from_x), int(from_y))
|
||||||
self.auto.input_handler.set_active()
|
self.auto.input_handler.set_active()
|
||||||
self._background_mouse(win32con.WM_MOUSEMOVE, from_x, from_y)
|
self._background_mouse(win32con.WM_MOUSEMOVE, from_x, from_y)
|
||||||
@@ -325,10 +342,16 @@ class AalcEngine(Engine):
|
|||||||
time.sleep(float(duration) / steps)
|
time.sleep(float(duration) / steps)
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
finally:
|
finally:
|
||||||
|
# 同 click(): 透明度必须在嵌套的 finally 里还原, 不能被还原位置那步的
|
||||||
|
# 异常跳过, 否则窗口会一直隐形。
|
||||||
|
try:
|
||||||
self._background_mouse(win32con.WM_LBUTTONUP, last_x, last_y)
|
self._background_mouse(win32con.WM_LBUTTONUP, last_x, last_y)
|
||||||
if position is not None:
|
if position is not None:
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
self._restore_background_position(position)
|
self._restore_background_position(position)
|
||||||
|
finally:
|
||||||
|
if transparent:
|
||||||
|
self.screen.handle.set_window_transparent(False)
|
||||||
return
|
return
|
||||||
if not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
if not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
||||||
import pyautogui
|
import pyautogui
|
||||||
|
|||||||
Reference in New Issue
Block a user