-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmousewalk.py
More file actions
executable file
·50 lines (35 loc) · 910 Bytes
/
mousewalk.py
File metadata and controls
executable file
·50 lines (35 loc) · 910 Bytes
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
import time
import tkinter as tk
from pynput.mouse import Controller
from pynput.mouse import Listener
root = tk.Tk()
mouse = Controller()
w, h = root.winfo_screenwidth() - 1, root.winfo_screenheight() - 1
print(f'mouse walking on {w+1, h+1} screen')
# Exit on user input
x_prev, y_prev = mouse.position
going_exit = False
def on_move(x, y):
global x_prev, y_prev, going_exit
if abs(x_prev - x) != abs(y_prev - y):
going_exit = True
return False
x_prev, y_prev = x, y
listener = Listener(on_move=on_move)
listener.start()
# Walk
move_x = 1
move_y = 1
while True:
mouse.move(move_x, move_y)
time.sleep(0.001)
if mouse.position[1] >= h:
move_y = -1
if mouse.position[1] <= 1:
move_y = 1
if mouse.position[0] >= w:
move_x = -1
if mouse.position[0] <= 1:
move_x = 1
if going_exit:
break