Skip to content

Commit 51d649b

Browse files
authored
Merge pull request #111 from medicinemelancholy/pr1
ImportTask缩小首个图片搜索范围,新增鼠标移动支持
2 parents 98981c2 + 927b0de commit 51d649b

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

src/tasks/fullauto/ImportTask.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from pathlib import Path
1212
from PIL import Image
13-
from ok import Logger, TaskDisabledException
13+
from ok import Logger, TaskDisabledException, GenshinInteraction
1414
from ok import find_boxes_by_name
1515
from src.tasks.DNAOneTimeTask import DNAOneTimeTask
1616
from src.tasks.CommissionsTask import CommissionsTask, Mission, QuickMoveTask
@@ -222,9 +222,11 @@ def match_map(self, index, max_conf=0):
222222
max_index = None
223223

224224
for i, name in enumerate(self.img):
225+
if index is None and not re.search(r'[a-zA-Z]$', name):
226+
continue
225227
if index is not None and not (index in name and len(name) - len(index) <= 3):
226228
continue
227-
if index == name:
229+
if index is not None and index == name:
228230
continue
229231
count += 1
230232
img = self.img[name]
@@ -292,12 +294,47 @@ def execute_key_action(self, action):
292294
action['key'] = normalize_key(action['key'])
293295
if action['key'] != 'f4':
294296
self.send_key_up(action['key'])
297+
elif action['type'] == "mouse_rotation":
298+
self.execute_mouse_rotation(action)
299+
elif action['type'] == "mouse_move":
300+
self.execute_mouse_move(action['dx'], action['dy'])
295301
else:
296302
raise
297303
except:
298304
self.log_info(f"不支持的按键-> type: {action['type']} key: {action['key']}")
299305
raise
300306

307+
def execute_mouse_rotation(self, action):
308+
direction = action.get("direction", "up")
309+
angle = action.get("angle", 0)
310+
sensitivity = action.get("sensitivity", 10)
311+
312+
pixels = angle * sensitivity
313+
314+
if direction == "left":
315+
dx, dy = -pixels, 0
316+
elif direction == "right":
317+
dx, dy = pixels, 0
318+
elif direction == "up":
319+
dx, dy = 0, -pixels
320+
elif direction == "down":
321+
dx, dy = 0, pixels
322+
else:
323+
logger.warning(f"未知的鼠标方向: {direction}")
324+
return
325+
self.execute_mouse_move(dx, dy)
326+
logger.debug(f"鼠标视角旋转: {direction}, 角度: {angle}, 像素: {pixels}")
327+
328+
def execute_mouse_move(self, dx, dy):
329+
interaction = self.executor.interaction
330+
_genshin_interaction = GenshinInteraction(
331+
interaction.capture, self.hwnd
332+
)
333+
# 确保窗口在前台
334+
self.hwnd.bring_to_front()
335+
_genshin_interaction.move_mouse_relative(int(dx), int(dy))
336+
337+
301338

302339
def normalize_key(key: str) -> str:
303340
"""
@@ -308,3 +345,4 @@ def normalize_key(key: str) -> str:
308345
if isinstance(key, str) and key.lower() == 'ctrl':
309346
return 'lcontrol'
310347
return key
348+

0 commit comments

Comments
 (0)