通过adb将触摸事件发送到设备 [英] send touch events to a device via adb
问题描述
我正在尝试使用 adb shell
命令将触摸事件发送到设备,以便为UI测试做一些基本的自动化操作。我已经在之前的一些讨论中关注了这一点。
I am trying to send touch events to a device using adb shell
command, so that I can do some basic automation for UI tests. I have followed the discussion in some previous threads regarding this.
我确认要获取事件并使用 sendevent
,每次触摸发送6个事件(xcoord,ycoord ,用于新闻的 2
,用于发布的 2
),使用可以轻松使用此信息sendevent
,但是用于触摸屏设备的 getevent
命令似乎会生成太多事件。
I confirmed about getting the events and using sendevent
, to send out 6 events for each touch ( xcoord, ycoord, 2
for press, 2
for release) and it was easy to use this information with sendevent
, but the getevent
command for the touchscreen device seems to generate far too many events.
有人设法将触摸事件从 adb
发送到设备吗?您能否分享解决方案。
Has somebody managed to send touch event from adb
to a device? Could you please share the solution.
我正在记录电话上的触摸事件。之后,我希望将同一事件作为UI测试的一部分发送回设备。
I am working on recording the touch events on phone. After that I wish to send the same event back to the device as part of UI testing.
请帮助
推荐答案
Android随附了一个 input
命令行工具,该工具可以模拟其他输入事件。
要模拟一个点击
,使用:
Android comes with an input
command-line tool that can simulate miscellaneous input events.
To simulate a tap
, use:
input tap x y
运行 input
命令远程使用 adb shell
:
adb shell input tap x y
其他选项是:
shell@m0:/ $ input
input
usage: input ...
input text <string>
input keyevent <key code number or name>
input [touchscreen|touchpad|touchnavigation] tap <x> <y>
input [touchscreen|touchpad|touchnavigation] swipe <x1> <y1> <x2> <y2> [duration(ms)]
input trackball press
input trackball roll <dx> <dy>
这篇关于通过adb将触摸事件发送到设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!