/Magisk-KeyboardRemaps

A Magisk module for remapping physical keyboard keys to Android software buttons.

Primary LanguageShellGNU General Public License v2.0GPL-2.0

What?

A simple Magisk module for Android which remaps physical hardware keys to any of Android's virtual software keycodes. For example, remapping your physical CAPS_LOCK key to KEYCODE_POWER (power button).

By default in release v1.0, the following keys are remapped:

  • CAPS_LOCK --> KEYCODE_POWER
  • NUMPAD_MULTIPLY --> KEYCODE_POWER

Why?

Why not? :)

How?

This is accomplished by modifying Vendor_ffff_Product_ffff.kl and Vendor_ffff_Product_ffff.kcm in /system/usr/keychars/. Thanks to Magisk, we can inject these files systemlessly without modifying the root filesystem; the net effect is the same.

This module has been tested to work with scrcpy in OTG mode (scrcpy --otg --hid-keyboard --hid-mouse). Android detects scrcpy's OTG mode as a Generic HID (specifically Device ffff with Vendor ffff), which is the same as any physical keyboard connected via USB.

This module has been tested to work on stock Android 11, 12 & 13, but should still be compatible back to Android 7.

Help?!

This module does not include any options for customization. However, doing so is trivial. If you wish to add or modify any key bindings, you can download the latest release, unpack the zip file, and modify Vendor_ffff_Product_ffff.kl as desired. The existing file contains my customizations, which are clearly notated. Refer to this page for a list of valid keycodes. Once finished, re-zip the module and install via Magisk.

See Issue #3 if you get stuck.

I said help!?

While I appreciate your interest in this module, I'm not offering support unless you have a specific question. Every Android device is different, and you will need to find, modify and inject the specific file which determines your keycode mappings.

Thanks to the following resources which helped me put this together:


Initial commit was 2022/03/22. Commit dates were squashed after performing a rebase.