36 lines
721 B
Python
36 lines
721 B
Python
from evdev import InputDevice, ecodes
|
|
import json
|
|
|
|
DEVICE_PATH = "/dev/input/event8"
|
|
|
|
device = InputDevice(DEVICE_PATH)
|
|
|
|
print("Press keys... Ctrl+C to stop")
|
|
print("Generating keymap from live input...\n")
|
|
|
|
keymap = {}
|
|
|
|
try:
|
|
for event in device.read_loop():
|
|
|
|
if event.type != ecodes.EV_KEY:
|
|
continue
|
|
|
|
if event.value != 1:
|
|
continue
|
|
|
|
key_name = ecodes.KEY.get(event.code, f"UNKNOWN_{event.code}")
|
|
|
|
clean = key_name.replace("KEY_", "").title()
|
|
|
|
print(f"{event.code} -> {clean}")
|
|
|
|
keymap[event.code] = clean
|
|
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
with open("keymap.json", "w") as f:
|
|
json.dump(keymap, f, indent=4)
|
|
|
|
print("\nSaved to keymap.json") |