一、input命令
查看输入设备:
$ getevent
input命令格式:
$ input -h
Usage: input [<source>] <command> [<arg>...]
The sources are:
mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
touchscreen
gamepad
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)
tmode <tmode>
二、模拟事件
input keyevent <keycode>
完整的keycode:
KeyEvent
常用keycode | 含义 |
---|---|
3 | HOME |
4 | 返回键 |
5 | 打开拨号应用 |
6 | 挂断电话 |
24 | 增加音量 |
25 | 降低音量 |
26 | 电源键 |
27 | 拍照(需要在相机应用里) |
64 | 打开浏览器 |
82 | 菜单键 |
85 | 播放/暂停 |
86 | 停止播放 |
87 | 播放下一首 |
88 | 播放上一首 |
122 | 移动光标到行首或列表顶部 |
123 | 移动光标到行末或列表底部 |
126 | 恢复播放 |
127 | 暂停播放 |
164 | 静音 |
176 | 打开系统设置 |
187 | 切换应用 |
207 | 打开联系人 |
208 | 打开日历 |
209 | 打开音乐 |
210 | 打开计算器 |
220 | 降低屏幕亮度 |
221 | 提高屏幕亮度 |
223 | 系统休眠 |
224 | 点亮屏幕 |
231 | 打开语音助手 |
276 | 如果没有 wakelock 则让系统休眠 |
-
电源键
input keyevent 26
-
菜单键
input keyevent 82
-
返回键
input keyevent 4
三、模拟屏幕动作
3.1 屏幕
屏幕上坐标的原点是屏幕的左上角
查看屏幕分辨率:
getprop
dumpsys window
获取控件坐标:
cd ~/Android/Sdk/tools
./uiautomatorviewer
3.2 滑动
input swipe <x1> <y1> <x2> <y2>
参数可以是负值
比如:
input swipe 300 1000 300 500
- 参数 300 1000 300 500 分别表示起始点x坐标 起始点y坐标 结束点x坐标 结束点y坐标。
- 从屏幕<300, 1000>滑动到 <300, 500>,这是一个向上滑动的动作
3.3 输入文本
在焦点处于某文本框时,可以通过 input 命令来输入文本
input text hello
3.4 点击
模拟手指在屏幕的点击
input tap <x> <y>
网友评论