Guide - How to remap keys on a hardware keyboard

This is a quick guide on how to remap keys for hardware keyboards.

You may have noticed that hardware keyboards often have a lot of keys that when used on Android devices either do nothing at all, or simply do not perform their intended function.  This guide will assist you in attempting to rectify this.

Some people do this by just editing generic.kl, this is not the best way to do it as this will effect all unknown keyboards you attach to the device in the future.  The proper way is outlined below (this way you can also copy this file between devices for use with that exact keyboard).

What do you need

  • Root
  • Terminal Emulator (or knowledge of ADB) - I will not be telling you how to use ADB in this guide
  • Root Explorer (or similar) or knowledge of ADB
  • Hardware Keyboard
  • Key test app (link provided in this guide)
  • Patience and time

Step One

Download this key test app from here - thanks to Chris Boyle for making this simple but useful app.

Step Two

Connect your keyboard (be that USB or bluetooth) and open Terminal Emulator app

Enter the following:

cat /proc/bus/input/devices

Find in the list displayed whichever one looks like your keyboard (usually you can tell by the brand name) and make a note of the Vendor and Product id’s e.g. 05ac and 258d

Step Three

Using Root Explorer (or similar) navigate to /system/usr/keylayout and copy the file ‘Generic.kl’.  Copy and Paste this file, then rename the copy to “Vendor_Product.kl”’

<vendorID> and <ProductID> being the two numbers you made a note of at the end of Step Two

Step Four

Decide which keys you wish to change and what function you would like to assign to them.

Step Five

Open up the test keys app and then press the key you want to change, on the screen it gives you the information for that key, you are looking for the ‘ScanCode’ number, this is how android can assign a function to that key.

Make a note of this number (if you want to change multiple keys then make a note of all their numbers and what function you wish it to have assigned)

Step Six

Open up ‘Vendor<vendorID>Product_<ProductID>.kl’ (you created in Step 3) in a text editor (remount then long press if you are using Root Explorer) and you will see a list of numbers on the left with their assigned function on the right.  In this list find the number for the key you identified in Step 4 (above).

When you have found that number you need to change the value assigned to the right to the function you want, e.g. for it to be a home key it should read HOME (all in capitals).

You can see most of the possible functions in the list already there, just scroll up and down and copy exactly what has been said, alternatively you can find them on the Google developer website.

Step Seven

Disconnect your hardware keyboard (if bluetooth, then simply turn off bluetooth) and reconnect and test your key.


Now you are done, repeat steps 3-6 for any further changes you wish to make.

Remember, you will need to do this for each device you use and also will need to redo it each time you change ROM on your device (unless you backup the Generic.kl file externally).

I strongly suggest you backup your newly made .kl file once you have mapped the keys to your liking, then you can easily restore should you never need to.