如何使用 ADB 使用 sendevent 命令将触摸事件发送到设备? [英] How to use ADB to send touch events to device using sendevent command?

查看:82
本文介绍了如何使用 ADB 使用 sendevent 命令将触摸事件发送到设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AndroidDebugBridge 将触摸事件发送到设备,以便我可以对 UI 测试进行一些基本的自动化.我已经关注了 LINK 中的讨论.我可以使用 sendevent 来模拟模拟器上的触摸,但无法在设备上执行相同操作.

I am trying to send touch events to a device using AndroidDebugBridge, so that I can do some basic automation for UI tests. I have followed the discussion in LINK. I am able to use sendevent to simulate touch on emulators, but unable to do the same on a device.

就像上面的链接一样,模拟器似乎为每次触摸发送了 6 个事件(xcoord、ycoord、2 个用于按下、2 个用于释放)并且使用此信息发送事件很容易,但是触摸屏的 getevent 用于设备似乎生成了太多事件.

Like in above link the emulator seems to send out 6 events for each touch ( xcoord, ycoord, 2 for press,2 for release) and it was easy to use this information to sendevents, but a getevent for the touchscreen for a device seems to generate far too many events.

有人设法将触摸从 ADB 发送到设备吗?能否请您分享解决方案.

Has somebody managed to send touch from ADB to a device? Could you please share the solution.

推荐答案

Android 自带一个 input 命令行工具,可以模拟各种输入事件.要模拟点击,它是:

Android comes with an input command-line tool that can simulate miscellaneous input events. To simulate tapping, it's:

input tap x y

可以使用 adb shell ( > 2.3.5) 远程运行命令:

You can use the adb shell ( > 2.3.5) to run the command remotely:

adb shell input tap x y

这篇关于如何使用 ADB 使用 sendevent 命令将触摸事件发送到设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆