Skip to content

Commit 45b9613

Browse files
committed
add draw script to controlling mouse tutorial
1 parent eae240e commit 45b9613

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

general/mouse-controller/draw.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import mouse
2+
import math
3+
import time
4+
5+
def draw_square(size):
6+
# click and hold the left mouse button
7+
mouse.press()
8+
mouse.move(size, 0, absolute=False, duration=0.2)
9+
mouse.move(0, size, absolute=False, duration=0.2)
10+
mouse.move(-size, 0, absolute=False, duration=0.2)
11+
mouse.move(0, -size, absolute=False, duration=0.2)
12+
# release the left mouse button
13+
mouse.release()
14+
15+
16+
def draw_circle(radius):
17+
# click and hold the left mouse button
18+
mouse.press()
19+
# move the mouse in a circle
20+
for i in range(0, 360, 5):
21+
# convert degrees to radians
22+
angle = math.radians(i)
23+
# calculate the x and y coordinates
24+
x = radius * math.cos(angle)
25+
y = radius * math.sin(angle)
26+
# move the mouse to the calculated position
27+
mouse.move(x, y, absolute=False, duration=0.01)
28+
# release the left mouse button
29+
mouse.release()
30+
31+
if __name__ == "__main__":
32+
# Place the mouse at the starting point and then call
33+
draw_square(200)
34+
time.sleep(1)
35+
draw_circle(10)

0 commit comments

Comments
 (0)