self.last_hotkey = None
def apply_mappings(self, maps):
"""
Applies custom mappings.
Takes in key/value of key to code and adds to map array.
NB: The map array hold the mapping of all key codes to the strings used to denoted them in configs.
"""
for key, code in maps.items():
logger.debug("Mapped " + key + " as (" + key + ") to code " + str(code))
self.map[code] = "(" + key + ")"
def watch_keyboard(self):
"""
Keyboard watcher - watches keyboard for events and triggers hotkeys by sending events to server according to config
# TODO: Use const from evdev instead of manually checking for cleaner code and no magic numbers
"""
logger.info("Watching for key presses on " + self.name + "...")
for event in self.keyboard_device.read_loop():
# print(categorize(event))
type = event.type # Event type - only interested in key event (EV_KEY)
code = event.code # KDB Scan Code
value = event.value # Value - up, down, hold.
# We only want event type 1, as that is a key press
# If key is already pressed, ignore event provided value not 0 (key unpressed)
if type == evdev.ecodes.EV_KEY:
Use const from evdev instead of manually checking for cleaner code and no magic numbers
https://github.com/Gum-Joe/2Keys/blob/e8da1fa6aaa961f99758db39b041af403fe0c8a4/detectors/detector-pi/detector/twokeys/watcher/watch_keyboard.py#L88
ddf16bf3c7cfe75abdae271bd57a0adde6695b58