5

I am using the following code to print keycodes and scancodes for my currently plugged-in keyboard:

import evdev

device = evdev.InputDevice('/dev/input/event8') 

for event in device.read_loop():
  if event.type == evdev.ecodes.EV_KEY:
    print((evdev.categorize(event).keycode))
    print((evdev.categorize(event).scancode))

Currently I have a German keyboard layout, because I wanted something else than US. When I press '#' I get the following output:
KEY_BACKSLASH
43
Obviously, that is wrong. On a US keyboard, that would be right.

So my question is: How can I get the correct keycode/scancode to the pressed key without a call to shell?

JJ Abrams
  • 365
  • 2
  • 11

0 Answers0