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

 

转载于:https://www.cnblogs.com/zzugyl/p/7515004.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值