How to map android keys to your usb/bluetooth keyboard

来源:互联网 发布:java gbk转utf8 乱码 编辑:程序博客网 时间:2024/05/29 16:44
I couldn’t tell if this was covered in another post, so I thought I would pass it on.


If you are using an external keyboard (via Bluetooth or usb), you may find that certain basic android key events (home, back and menu) are either missing or not logical. In my case, my Bluetooth keyboard had no way to return home or open menus for apps, requiring me to use both the edge hardware keys as well as the keyboard. To address this, you can try the following:


NOTE: While this worked for me, I can’t guarantee results for other keyboards. And, as always, back up files before making any changes.


Before you start, here are some helpful tools/links:
Android keymaps overview and handy tool – Within this site is a handy tool called “KeyTest” It is a very simple android app that helps you find what number corresponds to a given key on the keyboard.
Android keycodes – This page lists all the common android events that can be attached to a key. We are only going to look at the ones starting with “KEYCODE_”
1. Ensure your edge is rooted
2. Install the KeyTest apk file
3. Using your favorite file explorer (e.g. Root Explorer), go to /system/usr/keylayout
4. Back up the file “qwerty.kl” This is the document that contains the default mapping of keys to android functions.
5. Hook up your keyboard and make sure it is working
6. Run the KeyTest app – Every time you press a key on the keyboard (or one of the hardware keys on the lcd) the screen will update with Keycode (a number that relates to the Android action) and a scancode (the number that represents the key you actually pressed on the keyboard). Decide what keys you would like to use and jot down the scancode. You can use ctrl and fn keys in combination with other keys to get more unique scancodes.
7. Once you know the numbers (scancodes) for the keys you want to map, open up the qwerty.kl file with any convenient text editor. You will quickly see the general format for an entry – the word “key” followed by the number (scancode)* for the key followed by the android event in all caps. For example,


key 165 HOME
On my keyboard, this would mean that hitting fn + F7 (which generates a scancode of 165) will do the same as hitting the "home" key.




8. Save your modified “qwerty.kl” file in the same location as it was (/system/usr/keylayout) and reboot.


If all goes well, the next time you connect your keyboard you should be able to finally access all those important functions with logical (at least to you) keys.


*NOTE: You cannot use the same scancode number more than once!! If you do, your external keyboard will stop responding. Your edge software keyboard should work fine, so you should be able to recover your backup file and fix it.


Also, you can generally only map keys to normal keyboard activities (like DEL) or events that the edge has hardware keys for (MENU, BACK, HOME, SEARCH, VOLUME_UP , VOLUME_DOWN and the DPAD directions). While it would be nice to map a keystroke to automatically open email or the camera, those types of mappings do not appear to actually end up doing anything. As long as you have a backup you can probably play around without serious consequences.


From: http://www.mobileread.com/forums/showthread.php?t=159538


0 0
原创粉丝点击