Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError in events.py with JoyCon #91

Open
SarahCosmosys opened this issue Jun 18, 2018 · 1 comment
Open

KeyError in events.py with JoyCon #91

SarahCosmosys opened this issue Jun 18, 2018 · 1 comment

Comments

@SarahCosmosys
Copy link
Contributor

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.

@foxsam21
Copy link

This was mentioned with a suggested fix (and a pull request) in #75 (comment) maybe it can be merged one day.

gvalkov added a commit that referenced this issue Jan 11, 2020
Fix crash when handling unknown keys #91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants