zeth / inputs

Cross-platform Python support for keyboards, mice and gamepads
BSD 3-Clause "New" or "Revised" License
274 stars 88 forks source link

Library doesn't work when USB controller is plugged in while Python is running #87

Open geajack opened 4 years ago

geajack commented 4 years ago

I have a generic USB gamepad (non X-Box). If I plug it in before starting the Python interpreter, then get_gamepad() works as expected. However, if I start the Python interpreter and then run get_gamepad(), I get an UnpluggedError.

Based on what I saw in another ticket here, I tried to "refresh" the devices by calling DeviceManager(), but then I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3188, in __init__
    self._post_init()
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3200, in _post_init
    self._find_leds()
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3359, in _find_leds
    self._parse_led_path(path)
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3366, in _parse_led_path
    self.leds.append(SystemLED(self, path, name))
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3082, in __init__
    super(SystemLED, self).__init__(manager, path, name)
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3003, in __init__
    self._post_init()
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3086, in _post_init
    self._led_type_code = self.manager.get_typecode('LED')
  File "/home/jack/.local/lib/python3.7/site-packages/inputs.py", line 3421, in get_typecode
    return self.codes['type_codes'][name]
KeyError: 'LED'

And get_gamepad() continues to exhibit the same unexpected behavior.

I'm doing this on a Lenovo Yoga C930 with Ubuntu 19.10.

AndriyBench commented 1 year ago

Hey, did you ever figure this out? Im running into a simmilar issue where I have a program that can parse xbox controller input. If I plug in the Xbox controller and start the program, the controller will be recongnized but if I start the program and then plug in the controller the controller will not be recognized. I have a seperate "start" button that tells the program to kick off the xbox listening thread, which calls "events = get_gamepad()" command. I have a feeling this issue might be happening because of how the get_gamepad lib is getting initialized.... "from inputs import get_gamepad"