from evdev import InputDevice, list_devices, ecodes SCANCODES = {0x11A: "up", 0x148: "down", 0x147: "left", 0x107: "right", 0x106: "ok", 0x141: "play/pause", 0x11c: "power", 0x103: "vol+", 0x142: "vol-"} device = None last = 0x00 def do_action(action: str): if action == "ok": print("ok") for path in list_devices(): candidate = InputDevice(path) if candidate.name == "meson-ir": device = candidate break if device is None: raise RuntimeError("meson-ir input device not found") print(f"Listening on {device.path}: {device.name}") try: for event in device.read_loop(): if event.type == ecodes.EV_MSC and event.code == ecodes.MSC_SCAN: if (event.value != last): print(f"scancode {event.value:#x}") last = event.value action = SCANCODES.get(event.value) if action: print(f"got action {action}") do_action(action) else: print(f"repeat scancode {event.value:#x}") last = 0x00 except KeyboardInterrupt: print("\nExiting...") finally: device.close()