forked from tanjeffreyz/auto-maple
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistener.py
More file actions
49 lines (41 loc) · 1.4 KB
/
listener.py
File metadata and controls
49 lines (41 loc) · 1.4 KB
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
"""A keyboard listener to track user inputs."""
import config
import time
import utils
import threading
import keyboard as kb
from bot import Bot
class Listener:
def __init__(self):
"""Initializes this Listener object's main thread."""
self.thread = threading.Thread(target=Listener._main)
self.thread.daemon = True
def start(self):
"""
Starts listening to user inputs.
:return: None
"""
print('\nStarted keyboard listener.')
self.thread.start()
@staticmethod
def _main():
"""
Constantly listens for user inputs and updates variables in config accordingly.
:return: None
"""
while True:
if config.listening:
if kb.is_pressed('insert'):
Bot.toggle_enabled()
time.sleep(0.667)
elif kb.is_pressed('F6'):
Bot.load_routine(config.routine)
elif kb.is_pressed('F7'):
Bot.load_commands()
Bot.load_routine()
elif kb.is_pressed('F8'):
displayed_pos = tuple('{:.3f}'.format(round(i, 3)) for i in config.player_pos)
utils.print_separator()
print(f'Current position: ({displayed_pos[0]}, {displayed_pos[1]})')
time.sleep(1)
time.sleep(0.01)