Skip to content

KeyError in events.py with JoyCon #91

Description

@SarahCosmosys

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions