-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathcontrols.py
82 lines (56 loc) · 1.52 KB
/
controls.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
80
81
82
from pynput.keyboard import Key, Controller
import time
keyboard = Controller()
global key
global space_pressed
key = None
space_pressed = False
# for pressing the space
# keyboard.press(Key.space) and keyboard.release(Key.space)
# for pressing shift plus some key
# with keyboard.pressed(Key.shift):
# keyboard.press('a')
# keyboard.release('a')
def do_nothing():
global key
global space_pressed
# if space is pressed release it
if space_pressed:
keyboard.release(Key.space)
space_pressed = False
if key != None:
keyboard.release(key)
def move_left():
global key
global space_pressed
# if space is pressed release it
if space_pressed:
keyboard.release(Key.space)
space_pressed = False
if key == 'd':
keyboard.release(key)
key = 'a'
for i in range(100):
keyboard.press(key)
def move_right():
global key
global space_pressed
# if space is pressed release it
if space_pressed:
keyboard.release(Key.space)
space_pressed = False
if key == 'a':
keyboard.release(key)
key = 'd'
for i in range(100):
keyboard.press(key)
#print("key pressed")
def jump():
global key
global space_pressed
# if some other key is pressed release it
if key != None:
keyboard.release(key)
keyboard.press(Key.space)
space_pressed = True
#print("Space pressed")