New: XDA launches forum for app developers. Discuss coding, tools, marketing, and more.
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
tkolev
Old
#1  
tkolev's Avatar
Senior Member - OP
Thanks Meter 161
Posts: 790
Join Date: Sep 2008
Location: Sofia
Default [TUT] (Re)Mapping your USB keyboard

Most of you have a regular PC keyboard with a lot of unusable keys (win, f1-f12, pause, etc.) and here is how you can map those keys, so you can make the most of your keyboard. You can even remap the regular keys to change the layout of your keyboard if you like.

What you need to have:

1. An USB keyboard
2. Root access
3. Any root explorer that can mount /system as rw
4. Any terminal emulator
5. KeyEvent Display app found in the market

What you need to do:

1. Start the terminal emulator and type 'lsusb'. Connect the keyboard and type it again. Notice the device that is added (the keyboard) and write doen the two hex numbers (vendor id and product id).
2. Open the root explorer, go to /system/usr/keylayout/ and copy 'Generic.kl' to your /sdcard/ (or any location that is easy to find and edit the file). Rename the copied file to 'Vendor_xxxx_Product_xxxx.kl' replacing the xxxx with your vendor and product ids from the previous step.
3. Open the .kl file with any text editor and begin (re)mapping the keys. The file format is pretty straightforward:
key x CMD [OPT]
You need to know the scancode of the key you want mapped (x) and the command you want to execute when that key is pressed (CMD). The third parameter is optional and is useful if you want the action performed while the tab is sleeping (for example if you want to be able to wake it up).
4. To get the scancodes you need the KeyEvent Display app (probably there are others that do the same in the market) - just open it and press the key you want to map and notice the scancode value.
5. To find the usefull CMD values you can open the kaylayout file for the Acer BT keyboard and look at the CMDs there. For example EXPLORER opens the (default?) browser, KEYBOARD_UNLOCK gets you past the lock screen with just a press of a button, etc.
6. Once you are done with the mapping, save the file and copy it back to /system/usr/keylayout/ (you need to mount /system/ as rw first). I don't like editing in the /system/ folder, so any changes I do later are in the file located in /sdcard/ and then copy it back to /system/usr/keylayout/ (for some reason replacing the file doesn't work, so I have to delete it first and then copy it back)

You can edit the values in Generic.kl but this should affect all the keyboards that you connect, so it's better to create a specific .kl file for each one.

Any additions/corrections to this guide are welcome, especially if you know how to assign a key to launch a specific app, or how to open the app drawer (anything concerning the CMD values is highly appreciated)

Hope this helps someone!

Sent from my A500 using XDA Premium App
The Following 3 Users Say Thank You to tkolev For This Useful Post: [ Click to Expand ]
 
tomlogan1
Old
#2  
Senior Member
Thanks Meter 32
Posts: 205
Join Date: Oct 2007
Location: Ballwin
Default Keyboard Mapping

Thank you for this. I have a bluetooth keyboard with integrated mouse and wanted to get the values for Home, Back, and Recently Used apps. I use an HP HDMI to VGA to connect to an external monitor and once I remap the keyboard I can replace the laptop for this application.
 
tkolev
Old
#3  
tkolev's Avatar
Senior Member - OP
Thanks Meter 161
Posts: 790
Join Date: Sep 2008
Location: Sofia
Quote:
Originally Posted by tomlogan1 View Post
Thank you for this. I have a bluetooth keyboard with integrated mouse and wanted to get the values for Home, Back, and Recently Used apps. I use an HP HDMI to VGA to connect to an external monitor and once I remap the keyboard I can replace the laptop for this application.
Well, back is BACK, home is HOME, and you should be able to cycle through recent apps using alt+tab (not exactly the same as the recent apps button but close).

Sent from my A500 using XDA Premium App
 
samstheman42
Old
(Last edited by samstheman42; 7th November 2011 at 08:06 AM.)
#4  
Member
Thanks Meter 6
Posts: 82
Join Date: Nov 2010
Location: Boulder, CO

 
DONATE TO ME
Ok, so for clarification, let me make sure that I have this right because I seem to be getting stuck in the details somewhere.

Let's say that I want to remap the "s" key to be a "o" instead. My normal .kl file for the keyboard that I'm editing has things that look like this:
Quote:
key 31 S
Upon using the KeyEvent Display app for the "s" key, I see something like:
Quote:
^KeyDown: action=0 code=47 repeat=0 meta=0 scancode=31 mFlags=8 label='S' chars='null' number=' '
^KeyUp: action=1 code=47 repeat=0 meta=0 scancode=31 mFlags=8 label='S' chars='null' number=' '
And so then in my text editor, I should change my .kl file to read like:
Quote:
key 31 43
where scancode 31 is for the "s" key and code 43 would be what would come up for "o" in KeyEvent Display.

Is that correct?
 
tkolev
Old
#5  
tkolev's Avatar
Senior Member - OP
Thanks Meter 161
Posts: 790
Join Date: Sep 2008
Location: Sofia
Quote:
Originally Posted by samstheman42 View Post
Ok, so for clarification, let me make sure that I have this right because I seem to be getting stuck in the details somewhere.

Let's say that I want to remap the "s" key to be a "o" instead. My normal .kl file for the keyboard that I'm editing has things that look like this:


Upon using the KeyEvent Display app for the "s" key, I see something like:


And so then in my text editor, I should change my .kl file to read like:


where scancode 31 is for the "s" key and code 43 would be what would come up for "o" in KeyEvent Display.

Is that correct?
No. You should have "key 31 O". The scancodes are for getting the number of the "special" keys (win, context menu, media control, etc.) that cannot be easily identified in the .kl file.

Sent from my A500 using XDA Premium App
 
bergamin
Old
#6  
bergamin's Avatar
Member
Thanks Meter 3
Posts: 55
Join Date: Dec 2011
Location: Floripa
when i type lsusb in terminal it returns: lsusb: applet not found

what is going on? could you help me?

XDA PORTAL POSTS

Responses From Ubuntu Pouring Into Ubuntu Touch Q&A Thread

Ubuntu has become the most successful *nix distribution for a number of reasons, … more

Heimdall Suite 1.4.0 Released

The release version of Heimdall Suite 1.4.0 is now available after an epic wait. You may remember hearing about … more

A Guide to Paid Work on XDA-Developers

For the longest time, XDA has been a bastion, a pillar in the world of development. This is … more