python-evdev icon indicating copy to clipboard operation
python-evdev copied to clipboard

KeyError in events.py with JoyCon

Open SarahCosmosys opened this issue 7 years ago • 1 comments

I wrote a simple evdev program to read from a Nintendo Switch JoyCon and print out any buttons pressed.

from evdev import InputDevice, categorize, ecodes, KeyEvent

device = InputDevice("/dev/input/event17")

for event in device.read_loop():
    if event.type == ecodes.EV_KEY:
        keyevent = categorize(event)
        if keyevent.keystate == KeyEvent.key_down:
            print(keyevent.keycode)

And when I run the program it has an output like this

['BTN_A', 'BTN_GAMEPAD', 'BTN_SOUTH']
BTN_C
['BTN_NORTH', 'BTN_X']
['BTN_B', 'BTN_EAST']
BTN_THUMBR
BTN_TR2
BTN_Z
['BTN_WEST', 'BTN_Y']
BTN_START
BTN_MODE

But when I pressed the ZR button this happens

Traceback (most recent call last):
  File "test/button_lister.py", line 7, in <module>
    keyevent = categorize(event)
  File "/usr/lib/python3/dist-packages/evdev/util.py", line 46, in categorize
    return event_factory[event.type](event)
  File "/usr/lib/python3/dist-packages/evdev/events.py", line 97, in __init__
    self.keycode  = keys[event.code]  # :todo:
KeyError: 319

I am using Python version 3.5.2.

SarahCosmosys avatar Jun 18 '18 18:06 SarahCosmosys

This was mentioned with a suggested fix (and a pull request) in https://github.com/gvalkov/python-evdev/pull/75#issue-164981152 maybe it can be merged one day.

foxsam21 avatar May 20 '19 17:05 foxsam21