-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseControl.py
More file actions
61 lines (47 loc) · 1.96 KB
/
MouseControl.py
File metadata and controls
61 lines (47 loc) · 1.96 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
import pyautogui
import time
# Enable failsafe (move mouse to top-left corner to stop)
pyautogui.FAILSAFE = True
def move_mouse_smooth(x, y, duration=1):
"""Move mouse to position (x, y) smoothly over duration seconds"""
pyautogui.moveTo(x, y, duration=duration)
def move_mouse_relative(x_offset, y_offset, duration=0.5):
"""Move mouse relative to current position"""
pyautogui.moveRel(x_offset, y_offset, duration=duration)
def draw_square(size=200, duration=0.5):
"""Draw a square pattern with mouse movement"""
for _ in range(4):
pyautogui.moveRel(size, 0, duration=duration)
pyautogui.moveRel(0, size, duration=duration)
pyautogui.moveRel(-size, 0, duration=duration)
pyautogui.moveRel(0, -size, duration=duration)
def circle_pattern(radius=100, steps=36):
"""Move mouse in a circular pattern"""
import math
center_x, center_y = pyautogui.position()
for i in range(steps + 1):
angle = 2 * math.pi * i / steps
x = center_x + radius * math.cos(angle)
y = center_y + radius * math.sin(angle)
pyautogui.moveTo(x, y, duration=0.1)
# Example usage
if __name__ == "__main__":
print("Mouse movement script started!")
print("Move mouse to top-left corner to stop (failsafe)")
time.sleep(2) # Give user time to prepare
# Get current position
current_x, current_y = pyautogui.position()
print(f"Current position: ({current_x}, {current_y})")
# Move to specific position
print("Moving to center of screen...")
screen_width, screen_height = pyautogui.size()
move_mouse_smooth(screen_width // 2, screen_height // 2, duration=1)
time.sleep(0.5)
# Move in a circle
print("Drawing circle...")
circle_pattern(radius=100, steps=100)
time.sleep(0.5)
# Move back to original position
print("Returning to original position...")
move_mouse_smooth(current_x, current_y, duration=1)
print("Done!")