forked from adeelahmad/MacPilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_mouse.py
More file actions
100 lines (71 loc) · 2.97 KB
/
Copy pathdebug_mouse.py
File metadata and controls
100 lines (71 loc) · 2.97 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
"""
Debug Human Mouse Movement
Simple test to debug mouse movement issues.
"""
import sys
import asyncio
import time
import math
import random
from pathlib import Path
# Add automation framework to path
sys.path.insert(0, str(Path(__file__).parent / "automation_framework"))
import Quartz
async def simple_human_move(target_x: int, target_y: int, steps: int = 20):
"""Simple human-like mouse movement with debugging."""
print(f"Moving mouse to ({target_x}, {target_y}) in {steps} steps")
try:
# Get current position
current_pos = Quartz.CGEventGetLocation(Quartz.CGEventCreate(None))
start_x, start_y = int(current_pos.x), int(current_pos.y)
print(f"Starting from ({start_x}, {start_y})")
# Calculate step size
dx = (target_x - start_x) / steps
dy = (target_y - start_y) / steps
print(f"Step size: dx={dx:.2f}, dy={dy:.2f}")
# Move step by step
for i in range(steps + 1):
# Calculate position with slight curve
progress = i / steps
# Add a simple curve using sine wave
curve_offset = math.sin(progress * math.pi) * 20 # 20px curve height
current_x = start_x + (dx * i) + random.uniform(-2, 2) # Small wobble
current_y = start_y + (dy * i) + curve_offset + random.uniform(-2, 2)
print(f"Step {i}: Moving to ({current_x:.1f}, {current_y:.1f})")
# Create and post mouse event
move_event = Quartz.CGEventCreateMouseEvent(
None, Quartz.kCGEventMouseMoved, (int(current_x), int(current_y)), 0
)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, move_event)
Quartz.CFRelease(move_event)
# Wait before next step (using time.sleep instead of asyncio.sleep)
time.sleep(0.05) # 50ms delay
# Final position
final_event = Quartz.CGEventCreateMouseEvent(
None, Quartz.kCGEventMouseMoved, (target_x, target_y), 0
)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, final_event)
Quartz.CFRelease(final_event)
print(f"✅ Movement complete to ({target_x}, {target_y})")
return True
except Exception as e:
print(f"❌ Movement failed: {e}")
return False
async def main():
"""Test human mouse movement."""
if len(sys.argv) != 3:
print("Usage: python debug_mouse.py <x> <y>")
print("Example: python debug_mouse.py 400 300")
sys.exit(1)
target_x = int(sys.argv[1])
target_y = int(sys.argv[2])
print("🐭 Debug Human Mouse Movement")
print("=" * 40)
success = await simple_human_move(target_x, target_y)
if success:
print("🎉 Test completed successfully!")
else:
print("💥 Test failed!")
if __name__ == "__main__":
asyncio.run(main())