-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.py
More file actions
28 lines (21 loc) · 780 Bytes
/
Copy pathinput.py
File metadata and controls
28 lines (21 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Interception 驱动级输入封装"""
import random
import time as _time
import interception
_interception_ready = False
def _ensure_interception():
global _interception_ready
if not _interception_ready:
interception.auto_capture_devices()
_interception_ready = True
def hold_click_random(hold_min: float = 0.3, hold_max: float = 0.9) -> float | None:
"""在当前位置按下左键,随机长按后释放。返回实际长按秒数,失败返回 None。"""
try:
_ensure_interception()
interception.mouse_down("left")
hold_duration = random.uniform(hold_min, hold_max)
_time.sleep(hold_duration)
interception.mouse_up("left")
return hold_duration
except Exception:
return None