-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.py
47 lines (36 loc) · 1.11 KB
/
Input.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
# big copy paste of this: https://github.com/deagahelio/hmbg-input
import keyboard
class Action:
def __init__(self, name):
self.name = name
self.bound = []
self.down = False
self.pressed = False
self.released = False
def bind(self, key):
self.bound.append(key)
def update(self):
self.pressed = False
self.released = False
for key in self.bound:
if keyboard.is_pressed(key):
if not self.pressed and not self.down:
self.pressed = True
self.down = True
return
if not self.released and self.down:
self.released = True
self.down = False
actions = {}
def bind(key, action):
global actions
if actions.get(action) == None:
actions[action] = Action(action)
actions[action].bind(key)
def pressed(action): return actions[action].pressed
def released(action): return actions[action].released
def down(action): return actions[action].down
def update():
global actions
for action in actions.values():
action.update()