GitHub

Android external keyboard remapping without root

Since Android 4.1 an app can provide additional keyboard layouts via Key Character Map files. Since then, it's possible to customize a keyboard layout without root access by installing an app that contains requred layout. ExKeyMo helps you to build such app even if you don't know anything about Android development.

How to

  1. Create an app with your custom layout built-in. Use simple UI for key remapping. Use complex UI to provide your own Key Character Map file(s).
  2. Install the app. The app is self-signed so Android will warn you about untrusted source or something like this. Note: if you install the app and get an error, try to uninstall the previous version first, if you have any.
  3. Go to Settings -> Language & input -> Physical keyboard (the exact path may vary), choose the keyboard you want to customize, and select ExKeyMo Layout.

Layout customization

The keyboard layout is customized via Key Character Map file. To remap a physical key use map key SCAN_CODE ANDROID_KEY syntax where SCAN_CODE is the code that produced by the physical key and ANDROID_KEY is an Android key such as ENTER, BRIGHTNESS_UP or just a plain character like 1 or A. The default keyboard layout can be found in Generic.kl file in format key SCAN_CODE ANDROID_KEY.

For example you want to swap Caps Lock key and Esc key. To do this you need to map Caps Lock key to Esc key and vice versa. According to Generic.kl the default SCAN_CODE to ANDROID_KEY mapping these keys are 1 to ESCAPE and 58 to CAPS_LOCK. Now you can add desired mappings to your custom layout in format map key SCAN_CODE ANDROID_KEY. And don't forget to include default mappings by adding type OVERLAY as the very first line. The final result will be:

type OVERLAY

map key 58 ESCAPE
map key 1 CAPS_LOCK

Some keyboards have media-keys or other keys that don't work as expected. To remap them you should find out what scan codes they produce. There are several Android apps to do it. For example Gamepad tester.

More complex customization (combinations with modifier keys like Ctrl, Alt, Shift or producing non-English characters) is also possible. Learn more in official documentation.

Second Layout

A second layout is useful if you use multiple languages.

For example you still want to swap Caps Lock key and Esc key, but you need to do it for a language other than English. Find the default KCM-file for your language here. Add corresponding mappings. The final result will be:

# Multiple lines
# with content
# of
# KCM-file
# you copied
# from https://android.googlesource.com/platform/frameworks/base/+/master/packages/InputDevices/res/raw

map key 58 ESCAPE
map key 1 CAPS_LOCK

Validation

Unfortunately Android won't warn you if loaded KCM-file is incorrect and what errors are there. But there is web-version of validatekeymaps tool to validate the syntax of your KCM-file.

Limitations

Only two keyboard layouts are supported. It may be changed in the future. If you need multiple custom keyboard layouts (for example for multiple languages), take a look at Custom Keyboard Layout project.