Android keymaps
来源:互联网 发布:淘宝淘抢购 编辑:程序博客网 时间:2024/05/21 06:35
注:下文中的qwerty.kl不再有效,应使用Generic.kl或者Vendor_<vendorID>_Product_<productID>.kl,推荐使用Vendor_<vendorID>_Product_<productID>.kl,这样不会因为改错造成Generic.kl的混乱从而影响到其他外接键盘的使用。
I recently bought a Bluetooth keyboard to use on Android; unfortunately some keys weren't recognised at all and others weren't quite mapped as I'd like. This is fairly easy to fix as an end user, as long as you have a rooted device (adb remount
must succeed). Here's a quick howto, since I couldn't find one.
It shouldn't need saying, but you do this at your own risk. You can easily break your device's response to keys, and possibly make your device unbootable too if the file is invalid.
It's pretty much as described under Keymaps and Keyboard Input in the porting documentation. What we're going to do is edit one file: /system/usr/keylayout/qwerty.kl
. This file maps scancodes to Android keycodes. For example: key 30 A
means scancode 30 (decimal) maps toKEYCODE_A
(29), the A key. As the porting docs say, a separate Key Character Map file deals with what characters, if any (e.g. "a", "A", "#"), should be generated given the keycode and the state of the modifiers (Shift, Fn/Sym, etc). A different KCM can be loaded for Bluetooth keyboards depending on their device name, but at least by default, the same key layout file (including your changes) is used for Bluetooth and the built-in keyboard (if any).
So, first we need to fetch your current key layout, and it's a good idea to keep backups (both on the device and locally).
adb pull /system/usr/keylayout/qwerty.kl qwerty.klcp qwerty.kl qwerty-orig.kladb shell cp /system/usr/keylayout/qwerty.kl /sdcard/qwerty-orig.kl
Now, edit qwerty.kl
as you like. It should look initially look similar to this Nexus One example. You might find it helpful at this point to see what scancodes your keyboard is sending. There really ought to be a tool for this in Dev Tools or Spare Parts, but it seems there isn't. I've made a dirt-simple app to show you KeyEvent.toString(), which was the work of 5 minutes and could certainly be improved.
My particular keyboard is a white roll-up 87-key variety, that you can still find on eBay. It has F-keys doubling as media keys: if you get this model, be aware that the Fn key is really F-lock (toggles the state rather than acting as a modifier). Here is my layout file in case it's helpful. This layout mostly follows the principle of least surprise, except that the button with "Home" printed on it is Call, to mirror "End" being Hangup. F1 with F-lock on (Home symbol) is the Android "Home" keycode (goes to the home screen).
Now copy the layout back onto the device:
adb remountadb push qwerty.kl /system/usr/keylayout/qwerty.kl
(If the remount fails, you probably don't have a rooted device.) It seems you need to reboot for the changes to take effect, so go ahead and do that, and your keys should then behave as you've specified. :-)
附:bluetooth-keyboard-layout.txt内容如下
key 1 BACKkey 41 GRAVE# lower leftkey 86 BACKSLASH# print screenkey 99 CAMERA WAKE# home upper rightkey 102 CALL WAKE_DROPPED# menu lower leftkey 125 MENU# menu upper rightkey 126 MENU# menu icon upper right cornerkey 127 DPAD_CENTER# fn F1key 172 HOME WAKE# fn F4key 156 STAR# fn F5key 164 MEDIA_PLAY_PAUSE WAKE# fn F6key 163 MEDIA_NEXT WAKE# fn F7key 165 MEDIA_PREVIOUS WAKE# fn F8key 166 MEDIA_STOP# fn F11key 113 MUTE# fn F12 mediakey 171 FOCUS# pause breakkey 119 NOTIFICATION# ins lower rightkey 110 DPAD_CENTER# del lower rightkey 111 DELkey 399 GRAVEkey 2 1key 3 2key 4 3key 5 4key 6 5key 7 6key 8 7key 9 8key 10 9key 11 0key 158 BACK WAKE_DROPPEDkey 230 SOFT_RIGHT WAKEkey 60 SOFT_RIGHT WAKEkey 107 ENDCALL WAKE_DROPPEDkey 62 ENDCALL WAKE_DROPPEDkey 229 MENU WAKE_DROPPEDkey 139 MENU WAKE_DROPPEDkey 59 MENU WAKE_DROPPED#key 127 SEARCH WAKE_DROPPEDkey 217 SEARCH WAKE_DROPPEDkey 228 POUNDkey 227 STARkey 231 CALL WAKE_DROPPEDkey 61 CALL WAKE_DROPPEDkey 232 DPAD_CENTER WAKE_DROPPEDkey 108 DPAD_DOWN WAKE_DROPPEDkey 103 DPAD_UP WAKE_DROPPED#key 102 HOME WAKEkey 105 DPAD_LEFT WAKE_DROPPEDkey 106 DPAD_RIGHT WAKE_DROPPEDkey 115 VOLUME_UPkey 114 VOLUME_DOWNkey 116 POWER WAKEkey 212 CAMERAkey 16 Qkey 17 Wkey 18 Ekey 19 Rkey 20 Tkey 21 Ykey 22 Ukey 23 Ikey 24 Okey 25 Pkey 26 LEFT_BRACKETkey 27 RIGHT_BRACKETkey 43 BACKSLASHkey 30 Akey 31 Skey 32 Dkey 33 Fkey 34 Gkey 35 Hkey 36 Jkey 37 Kkey 38 Lkey 39 SEMICOLONkey 40 APOSTROPHEkey 14 DEL key 44 Zkey 45 Xkey 46 Ckey 47 Vkey 48 Bkey 49 Nkey 50 Mkey 51 COMMAkey 52 PERIODkey 53 SLASHkey 28 ENTER key 56 ALT_LEFTkey 100 ALT_RIGHTkey 42 SHIFT_LEFTkey 54 SHIFT_RIGHTkey 15 TABkey 57 SPACEkey 150 EXPLORERkey 155 ENVELOPE key 12 MINUSkey 13 EQUALSkey 215 AT
From: http://chris.boyle.name/blog/2010/08/android-keymaps/
- Android keymaps
- Android Keymaps and Keyboard Input
- Android Keymaps and Keyboard Input
- ANDROID Porting系列八、Keymaps and Keyboard Input
- Keymaps and Keyboard Input
- Keymaps and Keyboard Input
- AndroidStudio 已确认快捷键, 选择Keymaps: Mac OS X 10.5+
- Sublime Text3安装插件keymaps快捷键无效问题
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- linux /proc目录下的文件详解
- array 及 vector 的使用
- Coin Change
- Path Sum && Path Sum ||
- Effective C++ 条款49:了解new-handler的行为
- Android keymaps
- oracle分组汇总统计函数grouping
- Fruit
- Jconsole连接当地pid出错
- 《学会等待》有感
- 【POJ】【POJ刷水合集】【#2】
- 从零学习多线程第三篇--互斥量与条件变量的应用
- linux-suse-内存分析
- 设计模式--单例模式