0

In Python3, instances for gamepad controllers can be created using python-uinput module. The code may look something like this:

device = uinput.Device(list_of_events, name=name, bustype=0x06, vendor=0x2357, product=0x1, version=mode)

While I forced some values, where typically 0x06 means virtual, the vendor id is something that I picked and hope it does not collide with any other vendor, the product is 1 and the version is typically 1, I did not found any change with respect to the previous situation:

device = uinput.Device(list_of_events, name=name)

The list of events is long to explain, but let's say it is a gamepad with two axes and works "typically" as expected (D-Pad is discrete usage of ABS_X/ABS_Y axes, left analog is ABS_X/ABS_Y with analog usage, and right analog is ABS_RX/ABS_RY with analog usage).

While the pads work well until disconnected, under certain conditions or software (e.g. zsnes emulator) a new device instance (uinput.Device(...)) seems to not be recognized as a previous device instance even if both were created with the same name. For example, let's say I do this:

  1. I create an instance: device = uinput.Device(events, "My-Gamepad-1").
  2. I trigger the keys properly, configure the zsnes input with that device's events, and play a while.
  3. I disconnect my device: device.destroy().
  4. I create a new instance: device = uinput.Device(events, "My-Gamepad-1"). remember: the same happens if I add the arguments that I added in particular as in the beginnin of this question.
  5. I try to continue playing in the zsnes (even after closing it and opening it again), or perhaps I just try to re-configure the same input.

The problem is that, by step 5, my pad is not recognized in the ZSNES (a super nintendo emulator I took just for testing purposes of my virtual devices). As if it had a different internal identifier (perhaps not a product id, but instead a product instance id or something like that?). It is, however, still a recognized pad: I made a test program in Unity which can detect the pad, their buttons and their axes properly (in my case, the pad is detected as 0 and the axes are detected from it), but the mechanism might be different: Unity just needs to detect the pads being present, while the emulator settings need, perhaps, to match a pad id.

My question: I'd like to instantiate my uinput.Device objects in a way that, aside from not having issues in Unity, I don't have issues with software like zsnes.

Luis Masuelli
  • 12,079
  • 10
  • 49
  • 87
  • That's not really an option. What you are creating is a simulated kernel device, as if you were plugging in real USB devices. If you plug in your devices in a different order, they'll be seen as different physical devices. However, if you use the vendor ID and device ID of a REAL device that matches what you want, it should be recognized as such. – Tim Roberts May 28 '23 at 01:12
  • I don't use multiple devices, only one. So there's not a matter of order, but seems that something worse. – Luis Masuelli May 28 '23 at 03:13

0 Answers0