androidgamepadgamepad-api

How to switch axes of an android gamepad?


In my case I am using an Logitech F310 in Xinput mode (it has a switch to choose between DirectInput and Xinput). I wrote an small Application, which reads the axis values of the gamepad. It turns out that the right analog stick uses the axis MotionEvent.AXIS_RX and MotionEvent.AXIS_RY while the two shoulder analog triggers use the axis MotionEvent.AXIS_Z and MotionEvent.AXIS_RZ.

But according to the Documentation AXIS_Z and AXIS_RZ should be used for the right analog stick:

public static final int AXIS_RZ

Axis constant: Z Rotation axis of a motion event.

For a joystick, reports the absolute rotation angle about the Z axis. The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). On game pads with two analog joysticks, this axis is often reinterpreted to report the absolute Y position of the second joystick instead.

This is a problem in games, which don't offer options to remap buttons and analog sticks of gamepads. For example GTA San Andreas thinks that the two analog triggers are the right analog stick. But since the neutral value of the trigger, when it is not pressed, is -1 instead of 0, like it would be with an analog stick in neutral state, the camera is constantly spinning. (right analog stick is used for camera movement in this game)

Where is the axis mapping saved? Is it hard hardcoded within the gamepad? Or does it get assigned in the Linux device subsystem? Or maybe within the android InputDevice framework? If so, can it be changed?

Another possible solution could be to intercept the MotionEvents between the event dispatcher and the receiving App and change the axis values. Is this or something similar possible in android? Maybe even on a lower level: With root access it is possile to read raw input data from the /dev/input/event6 device (in my case event6 is the gamepad). Is it possible to constantly overwrite this file with adjusted axis values?


Solution

  • You need root access. Here you can find configs to different devices /system/usr/keylayout You can manual create new config for native support for needed device and write it to this folder. You can check key codes from your device with KeyTest app. Also you can copy existing config and edit it for your device and yours key codes.