So, I posted a very similar thread previously but it didn’t get any answers, so here goes again.
I’ve been working on a game for a while now, and with the latest update, I plan to add a more versatile control scheme customisation. I’ve got the custom kb/m inputs sorted now, but controllers still prove to be problematic.
Now, it’s relatively trivial in Blender to get controller input, but for DS4 and Steam controllers, the bge.logic.joysticks function doesn’t work particularly well. With the DS4, it doesn’t detect the d-pad (through the DS4 dongle), but it’s fine with everything else. With the Steam controller, it just messes up completely unless I’m also running Steam to make it emulate an xbox controller.
Is there any fix for the DS4, or is the only option sorting out libusb with PyUSB manually to get raw input? Would there be a way to automate this process when installing the game? On the bright side, if that’s the only option, I can always just access keyboards and mice separately, and even have split-screen with kb/m.
I think you know the according sensors which interact with the OS.
Unless you manage your OS to treat other devices as joystick or mouse (e.g. via drivers) there is no build-in support on them.
Python binding to other devices
The other option would be a custom Python controller acting as sensor. This means your Python code checks the device at each single frame. This is possible when you get a Python binding to the device. Be aware this might be OS-specific.
I think this is where you currently are.
Customizable input
At the moment it is pretty simple to reconfigure input of the same device (e.g. exchange keyboard keys with other keyboard keys, or mouse keys with other mouse keys). You can do that by reconfiguring the according sensor [assuming you know what the semantic meaning of what the sensor is supposed to measure]
The BGE is not designed to have a “generic input” (it was proposed but never implemented). Therefore it is very complex to exchange input of different devices (e.g. keyboard keys with mouse keys or joystick keys).
There is a simple solution on buttons:
implement game logic on message rather than on device sensors directly
add objects to send these messages on according input (reconfigurable)
Using non-boolean values is not so trivial but still possible the same way. You can have one object that deals with a joystick axis (others with devices by python binding). It sends a message when the value changed. The subject is identifying the meaning of the axis while the body contains the normalized value.
Example:
joystick axis 1 is value -2846 -> message body “up turn by” body: -0.3
The advantages are:
your game logic is not mixed with the various input handling logics
you can dynamically add/remove/exchange various input handlings
the input handling logic is isolated and can be treated separately
your game logic can focus on it’s own business and does not care where the input is coming from (as it gets normalized values)
multiple input handler possible at the same time
input handling and game logic does not need to reside in the same scene (but needs to live in currently running scenes)
the order of input procesing is preserved (your game logic will always be after the input) - means the game logic will not processed before the input logic. That could happen on Python binding processing as it has to run as controller.
you can easily imlement “touch screen” input (mouse over + mouse button)
There are drawbacks too:
the game logic events are always one frame behind. This can become a problem on games with very fast reaction time.
lots of messages
it is possible that the same input triggers multiple Python controllers (to measure the input and later the perform game logic)
I was mostly just hoping that there was a driver update or something that would enable the PS4 controller D-Pad instead of having to grab it myself with extra Python.