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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM