temp_mouse_control.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import subprocess
  2. import time
  3. import os
  4. def test_mouse_movement_cliclick():
  5. print("🐭 鼠标移动测试程序 (cliclick 版本)")
  6. print("=" * 40)
  7. # 检查 cliclick 是否安装
  8. try:
  9. result = subprocess.run(['which', 'cliclick'], capture_output=True, text=True)
  10. if result.returncode != 0:
  11. print("❌ cliclick 未安装")
  12. print("请先安装: brew install cliclick")
  13. return
  14. except:
  15. print("❌ 无法检查 cliclick 安装状态")
  16. return
  17. # 获取屏幕尺寸
  18. try:
  19. screen_width, screen_height = 2560, 1440 # 常见 Mac 分辨率,您可能需要调整
  20. center_x = screen_width // 2
  21. center_y = screen_height // 2
  22. print(f"假设屏幕尺寸: {screen_width} x {screen_height}")
  23. print(f"中心点坐标: ({center_x}, {center_y})")
  24. print("3秒后移动鼠标到屏幕中心...")
  25. for i in range(3, 0, -1):
  26. print(f"{i}...")
  27. time.sleep(1)
  28. # 使用 cliclick 移动鼠标
  29. command = f"cliclick m:{center_x},{center_y}"
  30. print(f"执行命令: {command}")
  31. result = subprocess.run(command, shell=True, capture_output=True, text=True)
  32. if result.returncode == 0:
  33. print("✅ cliclick 移动成功!")
  34. else:
  35. print(f"❌ cliclick 移动失败: {result.stderr}")
  36. except Exception as e:
  37. print(f"❌ 出错: {e}")
  38. if __name__ == "__main__":
  39. test_mouse_movement_cliclick()