aboutsummaryrefslogtreecommitdiff
path: root/main.py
blob: 27066e2973680a4deb35660bdd14ebbebab48067 (plain)
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
from evdev import InputDevice, list_devices, ecodes

device = None
last = 0x00

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
                # Do logic here
            else:
                print(f"repeat scancode {event.value:#x}")
                last = 0x00
except KeyboardInterrupt:
    print("\nExiting...")
finally:
    device.close()