aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/main.py b/main.py
index 462ad48..27066e2 100644
--- a/main.py
+++ b/main.py
@@ -15,12 +15,17 @@ if device is None:
print(f"Listening on {device.path}: {device.name}")
-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
+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()