項目中使用一個開發版,預留兩個usb接口。相似華碩TinkerBoard。html
一個用戶鏈接攝像頭,一個用於adb調試。結果就沒了鼠標的接口。
屢次切換鼠標和攝像頭插頭,很是不方便,帶攝像頭的app無法調試。
因而各類查資料,發現了adb shell input這個命令,堪稱神器。shell
$ adb shell input --help Error: Unknown command: --help Usage: input [<source>] <command> [<arg>...] The sources are: trackball joystick touchnavigation mouse keyboard gamepad touchpad dpad stylus touchscreen The commands and default sources are: text <string> (Default: touchscreen) keyevent [--longpress] <key code number or name> ... (Default: keyboard) tap <x> <y> (Default: touchscreen) swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) press (Default: trackball) roll <dx> <dy> (Default: trackball)
adb shell input相關的操做有text、keyevent、tap、swipe、(press、roll軌跡球這兩個操做已經無用)
分別對應輸入文本、功能鍵、點擊、滑動(長按)app
1. 輸入文本:
adb shell input text 12345
輸入12345文本spa
2. 功能鍵:
adb shell input keyevent 4 返回
adb shell input keyevent 66 肯定
adb shell input keyevent 67 刪除;更多的keyevent鍵對應code值參考 http://www.cnblogs.com/chengchengla1990/p/4515108.html3d
3. 點擊:
adb shell input tap 20 1000
點擊位置(20,1000)調試
4. 滑動(長按)
adb shell input swipe 10 20 100 200
從(10,20)滑動到(100,200)
長按的技巧
最後加一個參數,表示操做的時間ms,如
adb shell input swipe 100 200 500 600 900 從(100,200)滑動到(500,600)總花費900ms
adb shell input swipe 1400 400 1400 400 900 長按(1400,400) 900mscode