是否可以在 Android 上使用 adb 在触摸屏上产生连续滑动动作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25500567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:30:44  来源:igfitidea点击:

Is it possible to produce continuous swipe action on the touchscreen, with adb, on Android?

androidadbswipeswipe-gesture

提问by Ocelot

I'm trying to reproduce swipe action, with the help of adb. Currently, this code works (for swipe)

我正在尝试在 adb 的帮助下重现滑动操作。目前,此代码有效(用于滑动)

adb shell input touchscreen swipe 530 1420 530 1120
adb shell input touchscreen swipe 530 1120 830 1120

which is

这是

adb shell input touchscreen swipe x1,y1, x2,y2

but they are two discontinuous swipes.. Its equivalent to doing the first swipe, take ur hand off the screen and do the second swipe and so on..

但它们是两次不连续的滑动..相当于进行第一次滑动,将您的手从屏幕上移开,然后进行第二次滑动,依此类推..

I would like to achieve this as a single swipe.. Like, imagine a game where theres hot fire underneath and you have to drag om-nomacross various obstacles without taking your finger off om-nom.. with the above mentioned adb swipe, poor om-nomwould fall into the fire and become roasted-om-nom. :(

我想通过一次滑动来实现这一点.. 就像,想象一个游戏,下面有热火,你必须拖动om-nom穿过各种障碍物,而不能将手指从om-nom 上移开.. 使用上面提到的 adb 滑动,可怜的om-nom会掉进火里变成烤的 om-nom。:(

something like

就像是

adb shell input touchscreen swipe [(x1,y1, x2,y2), (x3,y3, x4,y4)...(xn-1,yn-1, xn,yn)]

if not adb, any other alternative?

如果不是adb,还有其他选择吗?

回答by HelgaM

You can do it in ADB. Use getevent to record your manual input with:

你可以在亚行中做到。使用 getevent 记录您的手动输入:

adb shell getevent

Or to record a specific device:

或录制特定设备:

adb shell getevent /dev/input/eventx

Then simuate recorded input with:

然后模拟记录的输入:

adb shell sendevent /dev/input/eventx

回答by Cornea Valentin

adb shell  "input touchscreen swipe 126 459 413 472 & input command touchscreen swipe 413 472 407 769"

You must run inside android device inputcommand, for continue swap add &between inputcommand, example below:

您必须在 android 设备输入命令中运行,以便在输入命令之间继续交换添加,示例如下:

adb shell "
   input touchscreen swipe 126 459 413 472 1000 & \ # 1th line 
   input touchscreen swipe 413 472 72  776 1000 & \ # 2th line
   input touchscreen swipe 72  776 407 769 1000 | echo done # 3th line" 


126 459   =   302 446   =   413 472
===================================
112 599   =   268 613   =   470 612
===================================
72  776   =   263 802   =   407 769

input touchscreen swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)

But need to make pausing or delaying (sleep,wait) between command's in order for more precise swipe.

但是需要在命令之间进行暂停或延迟(睡眠,等待)以实现更精确的滑动。

回答by Jay Spad

This works

这有效

$adb shell input touchscreen swipe x1 y1 & adb shell input touchescreen x2 y2 & adb shell input touchescreen x3 y3

$adb shell input touchscreen swipe x1 y1 & adb shell input touchescreen x2 y2 & adb shell input touchescreen x3 y3

回答by Haider

If your use case allows for slow swipe like within 2000ms, then the swipe is almost like a drag.

如果您的用例允许在 2000 毫秒内缓慢滑动,那么滑动几乎就像拖动一样。

shell input touchscreen swipe x1,y1, x2,y2 [duration]

shell input touchscreen swipe x1,y1, x2,y2 [duration]

回答by Thejus Krishna

I think this will be a good option

我认为这将是一个不错的选择

for i in {1..5}; do adb shell input touchscreen swipe 530 1420 530 1120; adb shell input touchscreen swipe 530 1120 830 1120; done