Files
Labstand-2.0/key_test.py
T

25 lines
853 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Простой тест: читает нажатия с /dev/input/event5 и печатает их в консоль."""
import sys
import evdev
from evdev import ecodes
PATH = sys.argv[1] if len(sys.argv) > 1 else '/dev/input/event5'
dev = evdev.InputDevice(PATH)
print(f"Открыто: {PATH} ({dev.name})")
print("Нажимайте клавиши. Ctrl+C для выхода.\n")
try:
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
name = ecodes.KEY.get(event.code, f'KEY_{event.code}')
if hasattr(name, 'keys'):
name = list(name.keys())[0]
state = {0: 'release', 1: 'press', 2: 'repeat'}.get(event.value, event.value)
print(f" {name:<18} {state}")
except KeyboardInterrupt:
print("\nВыход.")
finally:
dev.close()