jack 2 ماه پیش
والد
کامیت
3df7abcdec
3فایلهای تغییر یافته به همراه56 افزوده شده و 8 حذف شده
  1. 7 8
      main.py
  2. BIN
      requirements.txt
  3. 49 0
      temp_mouse_control.py

+ 7 - 8
main.py

@@ -4,9 +4,7 @@ import numpy as np
 import time
 import threading
 from pynput import keyboard
-from pynput.mouse import Button
 import os
-import subprocess
 
 class MacImageClicker:
     def __init__(self):
@@ -102,15 +100,16 @@ class MacImageClicker:
                 center_x = max_loc[0] + w // 2
                 center_y = max_loc[1] + h // 2
                 
-                # 在 macOS 上使用 pyautogui 点击
+                # 先记录当前位置
                 current_pos = pyautogui.position()
-                pyautogui.moveTo(center_x, center_y, duration=0.1)
-                pyautogui.click()
+                print(f"📍 从当前位置 ({current_pos.x}, {current_pos.y}) 移动到目标位置 ({center_x}, {center_y})")
                 
-                # 可选:移回原位置
-                # pyautogui.moveTo(current_pos.x, current_pos.y, duration=0.1)
+                pyautogui.moveTo(center_x, center_y, duration=0.0001)
+                                
+                # 执行点击
+                pyautogui.click()
                 
-                print(f"✅ 点击位置: ({center_x}, {center_y}), 相似度: {max_val:.3f}")
+                print(f"✅ 点击位置: ({center_x}, {center_y}), 相似度: {max_val:.3f}")
                 return True
                 
         except Exception as e:

BIN
requirements.txt


+ 49 - 0
temp_mouse_control.py

@@ -0,0 +1,49 @@
+import subprocess
+import time
+import os
+
+def test_mouse_movement_cliclick():
+    print("🐭 鼠标移动测试程序 (cliclick 版本)")
+    print("=" * 40)
+    
+    # 检查 cliclick 是否安装
+    try:
+        result = subprocess.run(['which', 'cliclick'], capture_output=True, text=True)
+        if result.returncode != 0:
+            print("❌ cliclick 未安装")
+            print("请先安装: brew install cliclick")
+            return
+    except:
+        print("❌ 无法检查 cliclick 安装状态")
+        return
+    
+    # 获取屏幕尺寸
+    try:
+        screen_width, screen_height = 2560, 1440  # 常见 Mac 分辨率,您可能需要调整
+        center_x = screen_width // 2
+        center_y = screen_height // 2
+        
+        print(f"假设屏幕尺寸: {screen_width} x {screen_height}")
+        print(f"中心点坐标: ({center_x}, {center_y})")
+        
+        print("3秒后移动鼠标到屏幕中心...")
+        for i in range(3, 0, -1):
+            print(f"{i}...")
+            time.sleep(1)
+        
+        # 使用 cliclick 移动鼠标
+        command = f"cliclick m:{center_x},{center_y}"
+        print(f"执行命令: {command}")
+        
+        result = subprocess.run(command, shell=True, capture_output=True, text=True)
+        
+        if result.returncode == 0:
+            print("✅ cliclick 移动成功!")
+        else:
+            print(f"❌ cliclick 移动失败: {result.stderr}")
+            
+    except Exception as e:
+        print(f"❌ 出错: {e}")
+
+if __name__ == "__main__":
+    test_mouse_movement_cliclick()