Android通过代码模拟物理、屏幕点击事件

来源:互联网 发布:股票交易软件源码 编辑:程序博客网 时间:2024/06/03 04:43

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:/ $

0 0
原创粉丝点击