evdevremapkeys icon indicating copy to clipboard operation
evdevremapkeys copied to clipboard

Emulate Xbox 360 gamepad

Open dariox86 opened this issue 4 years ago • 4 comments

Button mapping of most modern video games default to the Xbox 360 gamepad. There are several tools to remap my PlayStation 2 controller to a virtual Xbox 360 gamepad, the most popular being Xboxdrv. Unfortunately it seems these tools are not maintained anymore. Your application would gracely fill the gap if not for some missing feature:

  • EV_ABS type events with codes ABS_HAT0X and ABS_HAT0Y are not being delivered for some reason;
  • my gamepad has three event codes that don't have a name and I couldn't manage to specify these events by the raw code number (your tool reports them as "Unknown key");
  • it should be possible to specify a "range" parameter to convert the PlayStation 2 gamepad analog stick 8 bit precision to the Xbox 360 gamepad analog stick 16 bit precision, namely from an EV_ABS event with values from 0 to 255 to a corresponding EV_ABS event with values ranging from -32768 to +32767.

The new "range" parameter would automagically be used to convert an EV_KEY event to a EV_ABS one as well. This is needed because the Xbox 360 gamepad has some pressure-sensitive buttons with 8 bit precision that need to be mapped from the ordinary buttons on the PlayStation 2 gamepad, thus the EV_KEY event with value 1 (button pressed) would be translated to an EV_ABS event with value 255 (button fully pressed). Releasing the button would report an EV_ABS value to 0 again ("range: [255, 0]").

I think that the proposed enhancement should be very easy and elegant to implement. I would have done it myself but since I don't speak Python I find the code very hard to understand. With the proposed implementation the configuration file would look something like this:

devices:

  • input_name: 'HID 0b43:0003' # yes, this is the name of my PlayStation 2 adapter and it is successfully intercepted by evdevremapkeys output_name: Microsoft X-Box 360 pad remappings: BTN_THUMB2: code: BTN_SOUTH BTN_TOP: code: BTN_NORTH BTN_TRIGGER: code: BTN_WEST BTN_THUMB: code: BTN_EAST BTN_BASE4: code: BTN_START BTN_BASE3: code: BTN_SELECT BTN_BASE2: code: BTN_TR BTN_BASE: code: BTN_TL BTN_PINKIE: code: ABS_RZ type: EV_ABS # non pressure-sensitive button translated to 8 bit pressure sensitive one range: [255, 0] # 255 for button pressed and 0 for button released, nothing in-between in this case BTN_TOP2: code: ABS_Z type: EV_ABS range: [255, 0] BTN_BASE5: code: BTN_THUMBL BTN_BASE6: code: BTN_THUMBR BTN_DEAD: code: ABS_HAT0X # ABS_HAT0X and ABS_HAT0Y needed for directional buttons not being delivered (bug?) type: EV_ABS range: [-1, 0] # -1 for button pressed and 0 for button released, nothing in-between in this case +300: # event with no name preceded by + because it is a reserved character in C/C++ (feel free to think of something else to disambiguate from a C variable name) code: ABS_HAT0Y type: EV_ABS range: [-1, 0] +301: code: ABS_HAT0X type: EV_ABS range: [1, 0] +302: code: ABS_HAT0Y type: EV_ABS range: [1, 0] ABS_X: # no "code:" specified because we only need to reassign the range range: [-32768, 32767] # EV_ABS being converted from 8 bit 0-255 range to 16 bit -32768-+32767 with values in-between ABS_Y: range: [-32768, 32767] ABS_RZ: code: ABS_RX range: [-32768, 32767] ABS_Z: code: ABS_RY range: [-32768, 32767]

dariox86 avatar May 21 '20 02:05 dariox86

This is getting into SC-Controller type stuff, but that project has gotten big and super hairy, and outdated ( not ported to Python 3 yet ).

DanielJoyce avatar Aug 18 '20 17:08 DanielJoyce

Unfortunately there is no tool out there to fill the gap. They are either unmaintained or dependent upon older technologies.

dariox86 avatar Aug 18 '20 17:08 dariox86

Yeah, I'd like something 'simple' and then expand it further as needed. The core right now is simple. We could then add a module to support 'gamepads', and another to support mapping tablets. And finally a UI to help with mapping ( though nothing so fancy as showing a controller at first, more like "Press a button, how do you want it mapped?" )

DanielJoyce avatar Aug 19 '20 17:08 DanielJoyce

Minimalism in computing to me is paramount. Despite the long report, implementing those features should be pretty straightforward.

dariox86 avatar Aug 19 '20 17:08 dariox86