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