How To Map Joypad Axis To Button?
How do I map a joypad (specifically the HAT switch/DPad) axis to a button with a key-layout file in
/system/usr/keylayout/? I currently have this line in the appropriate file:
axis 0x10 split 0x7f BUTTON_L1 BUTTON_R1.
I'll explain the line token by token. First token refers to the input type.
axismeans I'm binding an axis.
Second token is the axis ID. The axis I want to remap is
The https://source.android.com/devices/input/key-layout-files concerning key-layout files mention you can split an input axis into two outputs with
splitso I'm using it. The split is at the value immediately following
split, in this case
Input values below the split threshold map as the 1st token after the split threshold token. Here it is
Input values above the split threshold map as the 2nd token after the split threshold token. Here it is
However, when I use the line metioned above the axis does not map to anything anymore. Are you able to map device axes to Android buttons in the first place? If so, what is the proper syntax for it?
From the https://source.android.com/devices/input/key-layout-files documentation:
A split axis maps a Linux axis code to two Android axis code names, such that values less than or greater than a threshold are split across two different axes when mapped. This mapping is useful when a single physical axis reported by the device encodes two different mutually exclusive logical axes.
In the example they split a combined gas/brake axis into separate
axis 0x01 split 0x7f GAS BRAKE
0x01is the Linux input event code https://github.com/torvalds/linux/blob/136057256686de39cc3a07c2e39ef6bc43003ff6/include/uapi/linux/input-event-codes.h#L816 . We're taking the
ABS_Xaxis with a logical range of
0x00< x <
0xFFand splitting it so that x >
0x7Fis mapped to https://developer.android.com/reference/android/view/MotionEvent#AXIS_GAS and values below
0x7Fare mapped to https://developer.android.com/reference/android/view/MotionEvent#AXIS_BRAKE .
axis 0x10 split 0x7f BUTTON_L1 BUTTON_R1
0x10is special, it's the Linux input event code https://github.com/torvalds/linux/blob/136057256686de39cc3a07c2e39ef6bc43003ff6/include/uapi/linux/input-event-codes.h#L827 which is a synthetic axis generated by the Linux input subsystem to make it easier to deal with hat switch inputs. Internally, HID gamepads don't represent D-pads as buttons or as separate X and Y axes. They're usually represented as a single rotational "hat switch" axis. Linux converts the rotational value into
ABS_HAT0Yaxes normalized to -1 < x < 1. These are seen as axis
0x11in the key layout mapping.
So, the first problem is your threshold is wrong. To split the
ABS_HAT0Xaxis you should use a threshold of 0.
The second problem is you're trying to map the split axes to button events, which isn't supported. You can only split an axis into separate axes.