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

 

posted @ 2017-09-13 15:02  水上云天  阅读(18672)  评论(1编辑  收藏  举报