-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_presses.py
79 lines (59 loc) · 1.31 KB
/
key_presses.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from imports import *
def on_press(key):
try:
print('alphanumeric key {0} pressed'.format(
key.char))
keys.append(str(key))
return False
except AttributeError:
print('special key {0} pressed'.format(
key))
return False
def on_release(key):
print('{0} released'.format(
key))
if key == keyboard.Key.esc:
# Stop listener
return False
def key_check():
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
def keys_to_output(keys):
if "'a'" in keys:
return [1,0,0]
elif "'d'" in keys:
return [0,0,1]
elif "'w'" in keys:
return [0,1,0]
else:
return [0,0,0]
def PressKey(key):
pyautogui.keyDown(key)
def ReleaseKey(key):
pyautogui.keyUp(key)
def straight():
PressKey('w')
ReleaseKey('a')
ReleaseKey('d')
time.sleep(0.09)
def left():
PressKey('a')
PressKey('w')
ReleaseKey('d')
ReleaseKey('a')
time.sleep(0.09)
ReleaseKey('w')
def right():
PressKey('d')
PressKey('w')
ReleaseKey('a')
ReleaseKey('d')
time.sleep(0.09)
ReleaseKey('w')
def slow_ya_roll():
#PressKey('s')
ReleaseKey('w')
ReleaseKey('a')
ReleaseKey('d')