复核驱动输入与窗口补丁,修复接管互斥和异常清理
This commit is contained in:
+42
-58
@@ -8,6 +8,7 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from .engine import Engine
|
from .engine import Engine
|
||||||
|
|
||||||
@@ -228,42 +229,41 @@ class AalcEngine(Engine):
|
|||||||
win32con.SWP_NOSIZE | win32con.SWP_NOZORDER |
|
win32con.SWP_NOSIZE | win32con.SWP_NOZORDER |
|
||||||
win32con.SWP_NOACTIVATE)
|
win32con.SWP_NOACTIVATE)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def _background_target(self, x, y):
|
||||||
|
position = None
|
||||||
|
transparent = self.cfg.win_input_type == 'window_move'
|
||||||
|
try:
|
||||||
|
if transparent:
|
||||||
|
self.screen.handle.set_window_transparent(True)
|
||||||
|
position = self.auto.input_handler._set_window_pos(int(x), int(y))
|
||||||
|
self.auto.input_handler.set_active()
|
||||||
|
yield position
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
if position is not None:
|
||||||
|
try:
|
||||||
|
time.sleep(0.12)
|
||||||
|
finally:
|
||||||
|
self._restore_background_position(position)
|
||||||
|
finally:
|
||||||
|
if transparent:
|
||||||
|
self.screen.handle.set_window_transparent(False)
|
||||||
|
|
||||||
def click(self, x, y, times=1):
|
def click(self, x, y, times=1):
|
||||||
self._prepare_input()
|
self._prepare_input()
|
||||||
if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'):
|
if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'):
|
||||||
import win32con
|
import win32con
|
||||||
handler = self.auto.input_handler
|
|
||||||
self.auto.wait_pause()
|
self.auto.wait_pause()
|
||||||
for _ in range(int(times)):
|
for _ in range(int(times)):
|
||||||
position = None
|
with self._background_target(x, y):
|
||||||
transparent = False
|
self._background_mouse(win32con.WM_MOUSEMOVE, x, y)
|
||||||
if self.cfg.win_input_type == 'window_move':
|
|
||||||
# 搬到光标下面时设成透明/点击穿透, 免得挡住用户的光标。
|
|
||||||
# ⛔ 必须在本次点击结束时就还原: 以前只有 background_screenshot
|
|
||||||
# 会把它恢复成 False, 于是"点击 -> 截图 -> 点击 -> 截图"这种
|
|
||||||
# 高频交替会让游戏窗口在不可见/可见之间反复切换 —— 肉眼看就是
|
|
||||||
# 画面一直抽搐。AALC 自己的 WindowMoveInput.mouse_click 根本不碰
|
|
||||||
# 透明度, 所以它只是"跳一下", 不会闪。
|
|
||||||
self.screen.handle.set_window_transparent(True)
|
|
||||||
transparent = True
|
|
||||||
position = handler._set_window_pos(int(x), int(y))
|
|
||||||
handler.set_active()
|
|
||||||
self._background_mouse(win32con.WM_MOUSEMOVE, x, y)
|
|
||||||
time.sleep(0.12)
|
|
||||||
self._background_mouse(win32con.WM_LBUTTONDOWN, x, y, held=True)
|
|
||||||
try:
|
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
finally:
|
|
||||||
# 嵌套 try/finally: 还原位置那步也可能抛错(比如任务被停),
|
|
||||||
# 但透明度**无论如何**都要还原, 否则窗口会一直隐形。
|
|
||||||
try:
|
try:
|
||||||
self._background_mouse(win32con.WM_LBUTTONUP, x, y)
|
self._background_mouse(win32con.WM_LBUTTONDOWN, x, y, held=True)
|
||||||
if position is not None:
|
time.sleep(0.12)
|
||||||
time.sleep(0.12)
|
|
||||||
self._restore_background_position(position)
|
|
||||||
finally:
|
finally:
|
||||||
if transparent:
|
self._background_mouse(win32con.WM_LBUTTONUP, x, y)
|
||||||
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':
|
||||||
@@ -318,40 +318,24 @@ class AalcEngine(Engine):
|
|||||||
if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'):
|
if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'):
|
||||||
import win32con
|
import win32con
|
||||||
self.auto.wait_pause()
|
self.auto.wait_pause()
|
||||||
position = None
|
with self._background_target(from_x, from_y) as position:
|
||||||
transparent = False
|
self._background_mouse(win32con.WM_MOUSEMOVE, from_x, from_y)
|
||||||
if self.cfg.win_input_type == 'window_move':
|
|
||||||
# 同 click(): 透明必须在本次拖动结束时就还原, 不能留给下一次截图
|
|
||||||
self.screen.handle.set_window_transparent(True)
|
|
||||||
transparent = True
|
|
||||||
position = self.auto.input_handler._set_window_pos(int(from_x), int(from_y))
|
|
||||||
self.auto.input_handler.set_active()
|
|
||||||
self._background_mouse(win32con.WM_MOUSEMOVE, from_x, from_y)
|
|
||||||
time.sleep(0.12)
|
|
||||||
self._background_mouse(win32con.WM_LBUTTONDOWN, from_x, from_y, held=True)
|
|
||||||
last_x, last_y = from_x, from_y
|
|
||||||
try:
|
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
steps = max(1, int(float(duration) / 0.02))
|
last_x, last_y = from_x, from_y
|
||||||
for step in range(1, steps + 1):
|
|
||||||
last_x = round(from_x + (to_x - from_x) * step / steps)
|
|
||||||
last_y = round(from_y + (to_y - from_y) * step / steps)
|
|
||||||
if position is not None:
|
|
||||||
self.auto.input_handler._set_window_pos(last_x, last_y)
|
|
||||||
self._background_mouse(win32con.WM_MOUSEMOVE, last_x, last_y, held=True)
|
|
||||||
time.sleep(float(duration) / steps)
|
|
||||||
time.sleep(0.12)
|
|
||||||
finally:
|
|
||||||
# 同 click(): 透明度必须在嵌套的 finally 里还原, 不能被还原位置那步的
|
|
||||||
# 异常跳过, 否则窗口会一直隐形。
|
|
||||||
try:
|
try:
|
||||||
self._background_mouse(win32con.WM_LBUTTONUP, last_x, last_y)
|
self._background_mouse(win32con.WM_LBUTTONDOWN, from_x, from_y, held=True)
|
||||||
if position is not None:
|
time.sleep(0.12)
|
||||||
time.sleep(0.12)
|
steps = max(1, int(float(duration) / 0.02))
|
||||||
self._restore_background_position(position)
|
for step in range(1, steps + 1):
|
||||||
|
last_x = round(from_x + (to_x - from_x) * step / steps)
|
||||||
|
last_y = round(from_y + (to_y - from_y) * step / steps)
|
||||||
|
if position is not None:
|
||||||
|
self.auto.input_handler._set_window_pos(last_x, last_y)
|
||||||
|
self._background_mouse(win32con.WM_MOUSEMOVE, last_x, last_y, held=True)
|
||||||
|
time.sleep(float(duration) / steps)
|
||||||
|
time.sleep(0.12)
|
||||||
finally:
|
finally:
|
||||||
if transparent:
|
self._background_mouse(win32con.WM_LBUTTONUP, last_x, last_y)
|
||||||
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