android adb shell input各種妙用

項目中使用一個開發版,預留兩個usb接口。類似華碩TinkerBoard。


一個用戶連接攝像頭,一個用於adb調試。結果就沒了鼠標的接口。
多次切換鼠標和攝像頭插頭,非常不方便,帶攝像頭的app沒法調試。
於是各種查資料,發現了adb shell input這個命令,堪稱神器。

$ 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軌跡球這兩個操作已經無用)
分別對應輸入文本、功能鍵、點擊、滑動(長按)

1. 輸入文本:
adb shell input text 12345
輸入12345文本

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.html

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) 900ms

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章