st-ten-1/src/test/evtest.py
2025-03-28 17:44:13 +01:00

33 lines
1.1 KiB
Python

import evdev
from evdev import InputDevice, categorize, ecodes
def capture_input_events():
try:
# List available input devices
devices = [InputDevice(path) for path in evdev.list_devices()]
for device in devices:
print(device.path, device.name, device.phys)
# Prompt the user to select a device
device_path = input("Enter the path of the device you want to capture (e.g., /dev/input/eventX): ")
device = InputDevice(device_path)
print(f"Capturing events from {device.name}...")
for event in device.read_loop():
if event.type == ecodes.EV_KEY:
print(categorize(event))
elif event.type == ecodes.EV_REL:
pass # print(categorize(event))
elif event.type == ecodes.EV_ABS:
pass # print(categorize(event))
else:
pass # print(event)
except FileNotFoundError:
print("Device not found.")
except KeyboardInterrupt:
print("Capture stopped.")
if __name__ == "__main__":
capture_input_events()