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

6

18

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

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-nom across various obstacles without taking your finger off om-nom.. with the above mentioned adb swipe, poor om-nom would fall into the fire and become roasted-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?

Bryophyte answered 26/8, 2014 at 7:46 Comment(5)
with adb? can you tell why?Bootjack
@Bootjack because I would like to do something without physically touching the phone.. just an experiment.Bryophyte
Very interesting as Im trying the same, doing the screen unlock via ADB, but as @Bryophyte I get 3 discontinous swipesZerlina
@CorvenDallas you can use unlock.sh script for that. To get the proper coords just use screencap to get a screenshot of your phone lockscreen.Hallerson
this answer may also help: https://mcmap.net/q/261165/-hold-and-move-using-adbAnallise
D
14

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

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
Dianadiandra answered 26/8, 2014 at 8:6 Comment(4)
Great suggestion.. trying it now.. already able to simulate hardware buttons :) .. will up-vote u if I get the desired output..Bryophyte
@Ocelot, Have you tried doing it this way ?. Using getevent and setevent, I was able to automate Actions/Taps.Ysabel
I tried what HelgaM suggested but that doesn't seem to work on the lock screen. I wanna simulate Pattern unlock.Bryophyte
@Bryophyte see this.Hallerson
E
5
adb shell  "input touchscreen swipe 126 459 413 472 & input command touchscreen swipe 413 472 407 769"

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

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.

Elasticize answered 15/5, 2018 at 20:22 Comment(4)
While this code snippet may solve the question, including an explanation helps to improve the quality of your response. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.Troostite
Well sorry , my English it's so bad but surely in future i will try to comment my answersElasticize
There is an edit link at the bottom of your post. You can use that to expand upon your answer.Troostite
This solution will result in 3 swipes being executed at the same time, not continuously. There is no way a sleep command can help.Zeniazenith
B
2

This one works for a pixel 6 pro. Adjust the 3rd parameter in your adb shell command according to your screen size. A few trial and errors should give you the right number. The below would do a right swipe 100 times.

for i in {1..100}
do
adb shell  "input touchscreen swipe 126 459 913 472"
done

Paste the code block as is in your terminal.

Bioenergetics answered 17/12, 2022 at 0:6 Comment(1)
Unfortunately on Xiaomi Poco 5X : java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission. However on a Samsung A51 it works!Damascene
P
1

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

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

Pattani answered 7/12, 2019 at 13:4 Comment(0)
P
-2

This works

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

Parkway answered 7/11, 2019 at 14:7 Comment(0)
H
-4

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
Hau answered 12/11, 2015 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.