#define DEBUG_RAW_EVENTS 1//0 修改为1,打开调试信息
#if DEBUG_RAW_EVENTS LOGD("Input event: device=%d type=0x%04x scancode=0x%04x " "keycode=0x%04x value=0x%08x flags=0x%08x", rawEvent->deviceId, rawEvent->type, rawEvent->scanCode, rawEvent->keyCode, rawEvent->value, rawEvent->flags); #endif
2.编译系统源码,升级固件,连接好蓝牙键盘,点击ESC键,观察打印消息中scancode的值,可以得到对应的scancode为0x000000ac,即172,这样就得到了扫描码。
3.在adb shell中查看输入设备信息:
shell@android:/ $ cat /proc/bus/input/devices
I: Bus=0005 Vendor=05ac Product=0239 Version=0001 N: Name="Bluetooth 3.0 Keyboard" ...(略)
shell@android:/ $ ls /system/usr/keylayout ls /system/usr/keylayout ACCDET.kl AVRCP.kl Generic.kl Vendor_045e_Product_028e.kl Vendor_046d_Product_c216.kl Vendor_046d_Product_c294.kl Vendor_046d_Product_c299.kl Vendor_046d_Product_c532.kl Vendor_054c_Product_0268.kl Vendor_05ac_Product_0239.kl Vendor_22b8_Product_093d.kl mtk-kpd.kl qwerty.kl这里可以看到有很多输入设备的按键映射配置文件,其中Vendor_05ac_Product_0239.kl是蓝牙键盘的转换表。
shell@android:/ $ cat /system/usr/keylayout/Generic.kl | busybox grep BACK cat /system/usr/keylayout/Generic.kl | busybox grep "BACK " key 158 BACK WAKE_DROPPED
e:\android\doc\bluetooth keyboard\keylayout>adb pull /system/usr/keylayout pull: building file list... pull: /system/usr/keylayout/qwerty.kl -> ./qwerty.kl pull: /system/usr/keylayout/mtk-kpd.kl -> ./mtk-kpd.kl pull: /system/usr/keylayout/Vendor_22b8_Product_093d.kl -> ./Vendor_22b8_Product_093d.kl pull: /system/usr/keylayout/Vendor_05ac_Product_0239.kl -> ./Vendor_05ac_Product_0239.kl pull: /system/usr/keylayout/Vendor_054c_Product_0268.kl -> ./Vendor_054c_Product_0268.kl pull: /system/usr/keylayout/Vendor_046d_Product_c532.kl -> ./Vendor_046d_Product_c532.kl pull: /system/usr/keylayout/Vendor_046d_Product_c299.kl -> ./Vendor_046d_Product_c299.kl pull: /system/usr/keylayout/Vendor_046d_Product_c294.kl -> ./Vendor_046d_Product_c294.kl pull: /system/usr/keylayout/Vendor_046d_Product_c216.kl -> ./Vendor_046d_Product_c216.kl pull: /system/usr/keylayout/Vendor_045e_Product_028e.kl -> ./Vendor_045e_Product_028e.kl pull: /system/usr/keylayout/Generic.kl -> ./Generic.kl pull: /system/usr/keylayout/AVRCP.kl -> ./AVRCP.kl pull: /system/usr/keylayout/ACCDET.kl -> ./ACCDET.kl 13 files pulled. 0 files skipped. 262 KB/s (27925 bytes in 0.104s)
key 172 BACK WAKE_DROPPED
e:\android\doc\bluetooth keyboard\keylayout>adb remount e:\android\doc\bluetooth keyboard\keylayout>adb push Vendor_05ac_Product_0239.kl /system/usr/keylayout/ e:\android\doc\bluetooth keyboard\keylayout>adb reboot
7.同样方法,添加好锁屏键、搜索键,并验证好了,就可以把修改添加到源码中,重新编译,升级固件验证:
frameworks/base/data/keyboards/Vendor_05ac_Product_0239.kl
验证后,不要忘记去掉调试信息。