-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.py
70 lines (44 loc) · 1.67 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class InputManager:
def __init__(self):
self._code_to_press_dict = {}
# Pre-init the values to false
for i in range(256):
self._code_to_press_dict[i] = False
# Init Special Keys
self._name_to_code_dict = {
"BACKSPCE" : 8,
"TAB" : 9,
"ENTER" : 13,
"SHIFT" : 16,
"CTRL" : 17,
"ALT" : 18,
"ESCAPE" : 27,
"SPACE" : 32,
"LEFT" : 37,
"UP" : 38,
"RIGHT" : 39,
"DOWN" : 40
}
# Init Numbers
for i in range(10):
self._name_to_code_dict[str(i)] = i+48
# Init Letters
alpha = [ "A","B","C","D","E","F","G","H","I","J","K","L","M",
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(65,91):
self._name_to_code_dict[alpha[i-65]] = i
########################################################## MOUSE ##################################################################
######################################################### KEYS ####################################################################
def press_key(self,key_code):
self._code_to_press_dict[key_code] = True
def release_key(self,key_code):
self._code_to_press_dict[key_code] = False
def check(self,*args):
name_to_press_dict = {}
for name in args:
code = self._name_to_code_dict.get(name)
code = name if code is None else code # If name is None, then either arg is key code or missing key name
is_pressed = self._code_to_press_dict.get(code)
is_pressed = False if is_pressed is None else is_pressed # If still None, then key does not exist
name_to_press_dict[name] = is_pressed
return name_to_press_dict