-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuto Keyboard Button Presser.py
61 lines (45 loc) · 1.56 KB
/
Auto Keyboard Button Presser.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Auto Keyboard Button Presser by Jminding - based off of the Auto Clicker code
"""
from pynput.keyboard import Key, Controller, Listener, KeyCode
import time
import pynput
import threading
delay = 0.001 # change this to change the delay between keypresses in seconds
key = "3" # change this to change which key is pressed
start_stop_key = KeyCode(char='®') # change this to change what combination of keypresses activates this
exit_key = KeyCode(char='≈') # change this to change what combination of keypresses terminates the running of the code
class PressKey(threading.Thread):
def __init__(self, delay, key):
super().__init__()
self.delay = delay
self.key = key
self.running = False
self.program_running = True
def start_pressing(self):
self.running = True
def stop_pressing(self):
self.running = False
def exit(self):
self.stop_pressing()
self.program_running = False
def run(self):
while self.program_running:
while self.running:
keyboard.press(self.key)
keyboard.release(self.key)
time.sleep(self.delay)
keyboard = Controller()
press_thread = PressKey(delay, key)
press_thread.start()
def on_press(key):
if key == start_stop_key:
if press_thread.running:
press_thread.stop_pressing()
else:
press_thread.start_pressing()
elif key == exit_key:
press_thread.exit()
listener.stop()
with Listener(on_press=on_press) as listener:
listener.join()