Usage: input [<source>] <command> [<arg>...]
The sources are:
dpad
keyboard
mouse
touchpad
gamepad
touchnavigation
joystick
touchscreen
stylus
trackball
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)
draganddrop <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
1.模拟文本输入操作
adb shell input text abc -----模拟输入abc
2.通过键值模拟按键操作,键值参考
adb shell input keyevent 4 / adb shell input keyevent KEYCODE_BACK -----模拟按back键
3.通过坐标模拟点击操作
adb shell input tap 300 500 -----点击横坐标300纵坐标500的点
4.通过坐标模拟滑动操作
adb shell input swipe 200 300 500 300 100 -----从(200,300)的点划到(500,300)的点,滑动时间100ms
5.通过坐标模拟拖动操作
adb shell input draganddrop 100 1220 500 620 2000 -----从(100,1220)的点拖动到(500,620)的点,滑动时间2000ms
6.通过坐标模拟长按操作
adb shell input swipe 200 300 201 301 2000 -----从(200,300)的点划到(201,301)的点,滑动时间2000ms,由于划动距离短,在一个图标之内则主观显示为长按操作
7.模拟实体键长按操作
通过 getevent & 获取实体键键值
/dev/input/event4: 0001 0074 00000001
/dev/input/event4: 0000 0000 00000000
/dev/input/event4: 0001 0074 00000000
/dev/input/event4: 0000 0000 00000000
0074为电源键键值,转换为十进制为116,编写如下脚本
sendevent /dev/input/event4 1 116 1
sendevent /dev/input/event4 0 0 0
sleep 4
sendevent /dev/input/event4 1 116 0
sendevent /dev/input/event4 0 0 0
运行sh脚本可得长按电源键效果,详细参考android在adb下模拟长按事件
8.通过坐标/键值模拟同时按下两个键,用and连接
adb shell input keyevent KEYCODE_POWER and KEYCODE_MENU -----电源键亮屏并滑动解锁