合并前复核:补齐急停释放、整轮中止和计划任务时限

Browse Source
This commit is contained in:
yws
2026-10-22 07:32:58 +00:00
parent 8a9495b185
commit a74fda07e2
14 changed files with 324 additions and 111 deletions
+33 -13
View File
@@ -22,6 +22,7 @@
import ctypes
import os
import time
import threading
from ctypes import wintypes
from functools import lru_cache
@@ -106,6 +107,9 @@ class DriverInput:
self.log = log
self._dll = None
self._open = False
self._stopped = False
self._input_lock = threading.RLock()
self._pressed = set()
# ---------------------------------------------------------------- 生命周期
@@ -131,7 +135,14 @@ class DriverInput:
@property
def ready(self):
return self._open and self._dll is not None
return self._open and self._dll is not None and not self._stopped
def emergency_stop(self):
"""拒绝后续鼠标输入并释放本实例按住的按钮。急停线程另有退出超时。"""
self._stopped = True
with self._input_lock:
for button in tuple(self._pressed):
self.up(button)
def preflight(self):
"""返回 (能否用, 原因)。用之前调一次, 把不能用的原因说清楚。"""
@@ -152,12 +163,13 @@ class DriverInput:
# ---------------------------------------------------------------- 移动
def move_relative(self, dx, dy):
if not self.ready:
return False
if dx == 0 and dy == 0:
with self._input_lock:
if not self.ready:
return False
if dx == 0 and dy == 0:
return True
self._dll.moveR(int(dx), int(dy), True)
return True
self._dll.moveR(int(dx), int(dy), True)
return True
def move_to(self, sx, sy, tol=1, iters=10, settle=0.03):
"""把光标精确移到屏幕坐标 (sx, sy)。返回是否到位。"""
@@ -177,12 +189,19 @@ class DriverInput:
# ---------------------------------------------------------------- 按键
def down(self, button=1):
if self.ready:
self._dll.mouse_down(int(button))
with self._input_lock:
if not self.ready:
return False
button = int(button)
self._pressed.add(button)
self._dll.mouse_down(button)
return True
def up(self, button=1):
if self.ready:
self._dll.mouse_up(int(button))
with self._input_lock:
if self._open and self._dll is not None:
self._dll.mouse_up(int(button))
self._pressed.discard(int(button))
def click(self, sx, sy, times=1, tol=1):
"""先确认到位置, 再按下抬起。没到位就不点, 免得点错地方。"""
@@ -195,11 +214,12 @@ class DriverInput:
return False
for _ in range(int(times)):
try:
self._dll.mouse_down(1)
if not self.down(1):
return False
time.sleep(0.03)
finally:
self._dll.mouse_up(1)
return True
self.up(1)
return not self._stopped
def key_down(self, key):
if self.ready: