Android通过代码模拟物理、屏幕点击事件
2015-12-23 15:36
821 查看
http://blog.csdn.net/mad1989/article/details/38109689
在未root的手机上都可以用 adb shell 发送按键, 触摸屏事件,monkeytest就是用这些指令操作的。
使用 getevent -p 查看当前输入设备
使用下面两组指令发送 Power 键给手机:
sendevent /dev/input/event0 1 102 1
sendevent /dev/input/event0 1 102 0
使用 input 指令发送触摸点击事件:
input tap xxx, yyy
shell@mx5:/ $ input tap 400 800
shell@mx5:/ $ input touchscreen 400 800
Error: Unknown command: 400
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)
shell@mx5:/ $
在未root的手机上都可以用 adb shell 发送按键, 触摸屏事件,monkeytest就是用这些指令操作的。
使用 getevent -p 查看当前输入设备
使用下面两组指令发送 Power 键给手机:
sendevent /dev/input/event0 1 102 1
sendevent /dev/input/event0 1 102 0
使用 input 指令发送触摸点击事件:
input tap xxx, yyy
shell@mx5:/ $ input tap 400 800
shell@mx5:/ $ input touchscreen 400 800
Error: Unknown command: 400
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)
shell@mx5:/ $
相关文章推荐
- Android RadioButton 图片位置和大小
- android BitmapFactory.Options.inSampleSize用法说明
- Android Service 相关
- Android PullToRefresh 分析之四、扩展RecyclerView
- android开源框架
- 安卓加载大量图片
- Android 线性布局按比例显示
- android使用系统裁剪图片
- Android studio 编译报错 Error:Error converting bytecode to dex:
- Android判断横屏竖屏代码
- Android Activity生命周期以及Fragment生命周期的区别与分析
- Groovy的方法、闭包语法,接口的实现
- Android VideoView简单播放视频
- 如何去阅读Android的崩溃日志(crash log)和栈轨迹(stack trace)
- 分析android图片的抖动处理
- Android Studio你不知道的调试技巧
- 详细的Android Studio系列教程一--下载和安装
- Android View Scroller类,scrollTo(...)和scrollBy(...)方法
- Android点击非编辑框区域键盘隐藏
- 查看android系统日志缓冲区,在代码中获取日志