programming-bongocat/input_manager.py

58 lines
1.8 KiB
Python
Raw Normal View History

2018-12-10 22:05:51 +01:00
class InputManager:
currently_pressed_keys = []
left_paw_keys = [
"1", "2", "3", "4", "5",
"Q", "W", "E", "R", "T", "Y",
"A", "S", "D", "F", "G", "H",
"Z", "X", "C", "V", "B",
"Espace", "Oem_5", "Tab", "Capital", "Lshift",
"Lcontrol", "Lwin", "Lmenu", "Space",
"F1", "F2", "F3", "F4", "F5"
]
right_paw_keys = [
"6", "7", "8", "9", "0", "Oem_Plus", "Oem_4", "Back",
"U", "I", "O", "P", "Oem_6", "Oem_1", "Return",
"J", "K", "L", "Oem_3", "Oem_7", "Oem_2",
"N", "M", "Oem_Comma", "Oem_Period", "Oem_Minus", "Rshift",
"Rmenu", "Rwin", "Rcontrol",
"Up", "Left", "Down", "Right",
"Insert", "Home", "Prior", "Delete", "End", "Next",
"Snapshot", "Scroll", "Pause",
"Numpad0", "Numpad1", "Numpad2", "Numpad3", "Numpad4", "Numpad5", "Numpad6", "Numpad7", "Numpad8", "Numpad9",
"Numlock", "Divide", "Multiply", "Subtract", "Add", "Decimal",
"F6", "F7", "F8", "F9", "F10", "F11", "F12"
]
def on_update(self, down):
pass
def press_key(self, key):
if not key in self.currently_pressed_keys:
self.currently_pressed_keys.append(key)
self.on_update(True)
def release_key(self, key):
if key in self.currently_pressed_keys:
self.currently_pressed_keys.remove(key)
self.on_update(False)
def left_keys_pressed(self):
pressed = False
for key in self.currently_pressed_keys:
if key in self.left_paw_keys:
pressed = True
return pressed
def right_keys_pressed(self):
pressed = False
for key in self.currently_pressed_keys:
if key in self.right_paw_keys:
pressed = True
return pressed