17

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?

Ocelot
  • 1,733
  • 4
  • 29
  • 53

6 Answers6

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
HelgaM
  • 176
  • 6
  • Great suggestion.. trying it now.. already able to simulate hardware buttons :) .. will up-vote u if I get the desired output.. – Ocelot Aug 26 '14 at 08:49
  • 1
    @Ocelot, Have you tried doing it [this way](http://stackoverflow.com/questions/25363526/fire-a-pinch-in-out-command-to-android-phone-using-adb/25629952#25629952) ?. Using `getevent` and `setevent`, I was able to automate Actions/Taps. – Saurabh Meshram Sep 15 '14 at 09:26
  • 3
    I tried what HelgaM suggested but that doesn't seem to work on the lock screen. I wanna simulate Pattern unlock. – Ocelot Oct 09 '14 at 05:42
  • @Ocelot see [this](http://stackoverflow.com/questions/25500567/is-it-possible-to-produce-continuous-swipe-action-on-the-touchscreen-with-adb#comment58804317_25500567). – Treviño Feb 22 '16 at 15:56
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.

Cornea Valentin
  • 471
  • 6
  • 12
  • While this code snippet may solve the question, [including an explanation](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) 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. – Stefan Crain May 15 '18 at 20:48
  • Well sorry , my English it's so bad but surely in future i will try to comment my answers – Cornea Valentin May 15 '18 at 21:38
  • There is an [edit link](https://stackoverflow.com/posts/50358620/edit) at the bottom of your post. You can use that to expand upon your answer. – Stefan Crain May 15 '18 at 21:45
  • 2
    This solution will result in 3 swipes being executed at the same time, not continuously. There is no way a sleep command can help. – Toan Le Jun 22 '20 at 02:00
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]

Haider
  • 179
  • 3
  • 8
0

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Roehit Kadam
  • 101
  • 1
  • 11
-2

This works

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

Abito Prakash
  • 4,368
  • 2
  • 13
  • 26
Jay Spad
  • 1
  • 1
-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
Thejus Krishna
  • 1,755
  • 1
  • 19
  • 28