android藍芽鍵盤調試記錄

來源:互聯網
上載者:User

情況:
android平板已經可以和藍芽鍵盤串連,並可以輸入文本等,大部分按鍵可以正常響應。但有少數幾個按鍵不響應,ESC、鎖屏鍵、搜尋鍵。

調試步驟:
1.開啟鍵盤輸入的調試資訊,以便擷取按鍵的掃描碼:
frameworks/base/services/input/InputReader.cpp

#define DEBUG_RAW_EVENTS 1//0 修改為1,開啟調試資訊

在方法InputDevice::process()可以看到列印資訊如下:

#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=0001N: Name="Bluetooth 3.0 Keyboard"...(略)

這裡重點關注Vendor=05ac Product=0239,根據對應規則:
Vendor_<Vendor>_Product_<Product>.kl
應該在/system/usr/keylayout有檔案Vendor_05ac_Product_0239.kl,
查看一下,的確有這個檔案:

shell@android:/ $ ls /system/usr/keylayoutls /system/usr/keylayoutACCDET.klAVRCP.klGeneric.klVendor_045e_Product_028e.klVendor_046d_Product_c216.klVendor_046d_Product_c294.klVendor_046d_Product_c299.klVendor_046d_Product_c532.klVendor_054c_Product_0268.klVendor_05ac_Product_0239.klVendor_22b8_Product_093d.klmtk-kpd.klqwerty.kl

這裡可以看到有很多輸入裝置的按鍵映射設定檔,其中Vendor_05ac_Product_0239.kl是藍芽鍵盤的轉換表。

4.因為要求將ESC響應為BACK鍵,所以,在Generic.kl中找到BACK鍵的定義:

shell@android:/ $ cat /system/usr/keylayout/Generic.kl | busybox grep BACKcat /system/usr/keylayout/Generic.kl | busybox grep "BACK "key 158   BACK              WAKE_DROPPED

5.先將檔案Vendor_05ac_Product_0239.kl提取到電腦中:

e:\android\doc\bluetooth keyboard\keylayout>adb pull /system/usr/keylayoutpull: building file list...pull: /system/usr/keylayout/qwerty.kl -> ./qwerty.klpull: /system/usr/keylayout/mtk-kpd.kl -> ./mtk-kpd.klpull: /system/usr/keylayout/Vendor_22b8_Product_093d.kl -> ./Vendor_22b8_Product_093d.klpull: /system/usr/keylayout/Vendor_05ac_Product_0239.kl -> ./Vendor_05ac_Product_0239.klpull: /system/usr/keylayout/Vendor_054c_Product_0268.kl -> ./Vendor_054c_Product_0268.klpull: /system/usr/keylayout/Vendor_046d_Product_c532.kl -> ./Vendor_046d_Product_c532.klpull: /system/usr/keylayout/Vendor_046d_Product_c299.kl -> ./Vendor_046d_Product_c299.klpull: /system/usr/keylayout/Vendor_046d_Product_c294.kl -> ./Vendor_046d_Product_c294.klpull: /system/usr/keylayout/Vendor_046d_Product_c216.kl -> ./Vendor_046d_Product_c216.klpull: /system/usr/keylayout/Vendor_045e_Product_028e.kl -> ./Vendor_045e_Product_028e.klpull: /system/usr/keylayout/Generic.kl -> ./Generic.klpull: /system/usr/keylayout/AVRCP.kl -> ./AVRCP.klpull: /system/usr/keylayout/ACCDET.kl -> ./ACCDET.kl13 files pulled. 0 files skipped.262 KB/s (27925 bytes in 0.104s)

在Vendor_05ac_Product_0239.kl,增加一行即可:

key 172   BACK              WAKE_DROPPED

6.修改完成後重新掛載system分區為可讀寫,再檔案push到機器中,重啟機器,查看是否修改成功:

e:\android\doc\bluetooth keyboard\keylayout>adb remounte:\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

驗證後,不要忘記去掉調試資訊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.