This may be old, but I haven't found evidence that this has changed in all the years of Android. Full details are from an old AOSP github repo.
This will require root access as it requires you to edit system-level files.
Android uses the standard Linux input event device (/dev/event0) and driver as described in the linux/input.h kernel header file. For more information regarding standard Linux input drivers, please see Linux Input drivers at http://kernel.org.
Key Layout Map Selection of a Key Layout Map Key layout maps are
installed in /system/usr/keylayout
and /data/usr/keylayout
.
For each keyboard device xxx, set the android.keylayout.xxx
system
property (see Building New Device for help setting system properties).
If you don't specify a keylayout file, Android will default to
/system/usr/keylayout/qwerty.kl
.
File Format Key layout maps are stored on the device as UTF-8 text
files and have the following characteristics:
Comments: The pound symbol (#) denotes a comment and everything after
the pound symbol on a line is ignored.
Whitespace: All empty lines are
ignored. Key definitions: Key definitions follow the syntax key
SCANCODE KEYCODE [FLAGS...], where SCANCODE is a number, KEYCODE is
defined in your specific keylayout file (android.keylayout.xxx), and
potential FLAGS are defined as follows:
SHIFT: While pressed, the shift key modifier is set
ALT: While pressed, the alt key modifier is set
CAPS: While pressed, the caps lock key modifier is set
WAKE: When this key is pressed while the device is asleep, the device will wake up and the key event gets sent to the app.
WAKE_DROPPED: When this key is pressed while the device is asleep, the device will wake up and the key event does not get sent to the app.
Using the above commands to help, you could change the file from something like:
key 13 DPAD_UP
key 15 SHIFT
to:
key 13 SHIFT
key 15 DPAD_UP
This was a big nostalgia moment for me - I used to be really into
keyboard remapping back in the "new-ROM-every-other-afternoon" days.