-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.py
More file actions
20 lines (14 loc) · 693 Bytes
/
mouse.py
File metadata and controls
20 lines (14 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import ctypes
def move_mouse(x, y):
# Get the screen size.
screen_width = ctypes.windll.user32.GetSystemMetrics(0)
screen_height = ctypes.windll.user32.GetSystemMetrics(1)
# Scale the coordinates to the screen size.
x_scaled = int(x * screen_width)
y_scaled = int(y * screen_height)
# Move the mouse to the scaled coordinates. For mirroring the screen, swap x_scaled and screen_width - x_scaled.
ctypes.windll.user32.SetCursorPos(screen_width - x_scaled, y_scaled)
def click_mouse():
# Simulate a left mouse button click, when the hand is closed.
ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0)
ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0)