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:
- I create an instance:
device = uinput.Device(events, "My-Gamepad-1")
. - I trigger the keys properly, configure the zsnes input with that device's events, and play a while.
- I disconnect my device:
device.destroy()
. - 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. - 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.