First of all you can redefine the key of every input device attached and recognized by your Android device. Such input devices like a IR Remote, Bluetooth Keybord and any USB HID (wireless or cable). This means every Keyboard, Remote Controller, Mouse or Gamepad can be modified to your own needs:
What do you need:
- Root access to your device
- Root Explorer (I use ES FIle Explorer)
- Text Editor (I use the build in editor of ES File Explorer)
- Terminal
You can also edit/create your *.kl file on your computer
Helpfull android tools
Easy MOD (.kl files)
General Infos about Android key layout files (.kl)
Key layout files are located by USB vendor, product (and optionally version) id or by input device name. The following paths are consulted in order:- /system/usr/keylayout/Vendor_XXXX_Product_XXXX_Version_XXXX.kl
- /system/usr/keylayout/Vendor_XXXX_Product_XXXX.kl
- /system/usr/keylayout/DEVICE_NAME.kl
- /data/system/devices/keylayout/Vendor_XXXX_Product_XXXX_Version_XXXX.kl
- /data/system/devices/keylayout/Vendor_XXXX_Product_XXXX.kl
- /data/system/devices/keylayout/DEVICE_NAME.kl
- /system/usr/keylayout/Generic.kl
- /data/system/devices/keylayout/Generic.kl
When constructing a file path that contains the device name, all characters in the device name other than '0'-'9', 'a'-'z', 'A'-'Z', '-' or '_' are replaced by '_'.
Source: https://source.android.com/devices/input/key-layout-files.html
Note: Do not forget to
chmod 660 your own created xyz.kl files. Or use ES File Explorer to do so: Mark file (long press) >> More >> Properties >> Permissons [Change] to
rw- r- r- = (
Read: Owner, Group, Other |
Write: Owner)
List all connected input devices
Use the following command at a Terminal Emulator or via the Android Debug Bridge (ADB), to find your keyboard in the list and to get the Vendor ID, Product ID, Version ID or Device Name.
Code:
cat /proc/bus/input/devices
A good Android Terminal tool with large font size (to read on a TV screen)
https://play.google.com/store/apps/d...rminalemulator
Tipp: You can use also Gamepad tester to do so. Just press the key on the remote you want to mod and it will show you all the needed informations about the Vendor ID, Product ID, Version ID or Device Name at the bottom of the screen.
Overview of all Android Key Codes
At the following link you will find a overview of all possible Android key codes, that can be mapped to any ScanCode of your remote control, keybord or game controller in your key layout file.
Note: When using a the key codes you don't have to use the beginning KEYCODE_ at your key layout file.
Example:
Code:
KEYCODE_APP_SWITCH = APP_SWITCH
List of all key codes >> http://developer.android.com/reference/android/view/KeyEvent.html
Test your Keys and find the ScanCode
To check the already set ScanCode of any key, you can use Multilanguage Keymap Redefiner (MKR) or Gamepad tester. (see pictures for more details)
With Gamepad tester you can also create your device own *.kl dummy file for any keyboard or remote controller, straight saved to the right folder. And for sure, this file must be enhanced manually to your needs. But for a Gamepad it can create already the final *.kl file for your Gamepad, so you do not need any other tool (steps)
MKR
Gamepad tester
Enhanced MOD (remote.conf)
With the following described
enhanced modifications you can easily add any IR Remote Controler to also work with your android device. It helps you also in case some keys of your IR Remote aren't working (not set).
Note: A full description on how to generate your own remote.conf file for any other IR Remote Controler can be found already
>> here <<
The remote.conf file to modify can be found her: system/etc/remote.conf
Right now we will check only how to add the non working (not set) keys to our needs.
First we have to
check if debug is enabled in your
remote.conf file. Because without this setting we will see nothing whats going on/wrong.
If it is set to 0, change it to 1 and reboot your device.
Now open a Terminal session and enter the following commands
to get root access
to clean all debug messages
Now click that key on your remote control that does not even work when testing it with MKR or Gamepad tester
Code:
dmesg|grep "code is 0x"
To see only those messages on keys who are not set to our remote.conf file
You will see right now a masse like this:
Wrong custom code is 0xaabbcccc
So our needed ScanCode to set at
remote.conf is:
bb
Now we can set the right ScanCode to our
remote.conf and
*.kl files like this.
remote.conf
Vendor_XXXX_Product_XXXX.kl
So
0xbb is the key we press on our remote and
123 is the ScanCode to this key and it is set to in our *.kl file as
DPAD_UP
Tipps & Tricks
While your are generating your own configurations file I should finally also mention the follwing tipps & tricks I made.
Android Key Layout files (*.kl)
The one file who fits them all (Generic.kl)
There are always already a lot of Key Layout files included to you Android. The most important is the Generic.kl file. Because this file is always used in case there is no other specific file, created only to mach to one specific device. So in case there is no kl file that match to your device Vendor & Device ID or device name, Android will always use the Generic.kl file.
So it is not a good idea to change anything to the Generic.kl. Because this could mess up the function of other input devices, that have also no own *.kl file. So it is always better to create a specific key file for each individual input device.
Error solving while creating your own *kl file
Sometimes while creating your own key layout files, things do not work as they should. In those cases it is good to now what causes the issue.
One of my best practice to check if the issue comes from your own created file or not, is to move all already existing *.kl to a sub folder. So the system has only the one file you created. But keep in mind that now no other input device will work anymore until you copy them back to it original folder. And you should always have a mouse attached to your Android device. Becasue this will be the only device that works without any *.kl file.
Summary: Use a Mouse as input backup & remove all other *.kl files temporary.
General tipps while editing
Keep always a copy of the original configurations file as reference, by just renaming the original file like this:- remote.conf >> remote.conf_
- Generic.kl >> Generic.kl_