-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnomove.py
42 lines (33 loc) · 1.17 KB
/
nomove.py
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
import pyautogui
from pynput.keyboard import Key, Listener
from threading import Thread
# set state of loop to false
active = False
# loop that moves mouse back to center every 0.1 seconds (default speed)
def active_loop():
while active:
#print(pyautogui.position()) # position of mouse currently
# move mouse roughly to the center (1440p screen)
pyautogui.moveTo(1300, 700)
def on_release(key):
#print(key) # print key info
# key input to start of script
if key == Key.page_down:
global active
t1 = Thread(target = active_loop) # multithreaded to run 2 loops at the same time
# set the state of active
if active:
print("DISABLED")
active = False
else:
print("ENABLED")
active = True
t1.start() # start thread
# key input to end script
if key == Key.end:
print("Exiting")
return False
print("Press 'Page Down' to start/pause script\nPress 'End' to end script")
# listener loop that detects keyboard inputs, even in the background
with Listener(on_release=on_release) as listener:
listener.join()