0

I want to control an Android device programmatically via ADB.

Since I have to scroll a list, I tried to scroll via a command like:

adb shell input touchscreen swipe 935 500 789 500 1000

This works, but the problem is that Android adds a fling/rubber band effect. So when the swipe is done it still scrolls a bit further. But I need to scoll pixel-perfect so this approach doesn't work in the way I need it. Even when I increase the swipe duration to 3000ms it scrolls for some more pixels.

Is there maybe an easy trick to tell ADB/my device 'swipe but hold down the finger after moving for ~500ms before releasing the finger in order to prevent the fling effect'?

What I also tried is to control the events manually. Therefore I ran adb getevent, performed a swipe on the device and collected the output:

[...]
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 0035 000000fb
/dev/input/event6: 0003 0030 0000000a
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 0035 000000fa
/dev/input/event6: 0003 0030 0000000b
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 0036 000001b6
/dev/input/event6: 0003 0030 0000000c
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 0035 000000f9
/dev/input/event6: 0003 0030 0000000d
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 0035 000000f8
/dev/input/event6: 0003 0030 0000000e
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 0035 000000f7
/dev/input/event6: 0003 0030 0000000f
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 0030 00000000
/dev/input/event6: 0003 0039 ffffffff
/dev/input/event6: 0000 0000 00000000
/dev/input/event6: 0003 002f 0000000c
/dev/input/event6: 0003 0039 0000000c
/dev/input/event6: 0003 0035 000000f7
/dev/input/event6: 0003 0036 000001b6
/dev/input/event6: 0000 0000 00000000

I guess this should tell me that my event is /dev/input/event6 and I assume that the event codes I need are 0035, 0036 and 0039.

So I tried around a little bit and came up with an approach like:

adb shell sendevent /dev/input/event6 3 53 935
adb shell sendevent /dev/input/event6  0 0 0
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6  0 0 0
adb shell sendevent /dev/input/event6 3 57 1
adb shell sendevent /dev/input/event6  0 0 0
adb shell sendevent /dev/input/event6 3 53 789
adb shell sendevent /dev/input/event6  0 0 0
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6  0 0 0
adb shell sendevent /dev/input/event6 3 57 0
adb shell sendevent /dev/input/event6  0 0 0

This is also done similarly here. But it didn't work at all, nothing changed on the device. Since I don't know what to try next or if my approach is correct at all, I'd like to ask you if you could tell me where my mistakes are.

Thanks!

C.M.
  • 713
  • 8
  • 18
  • Possible duplicate of [Is it possible to produce continuous swipe action on the touchscreen, with adb, on Android?](https://stackoverflow.com/questions/25500567/is-it-possible-to-produce-continuous-swipe-action-on-the-touchscreen-with-adb) – Martin Zeitler Feb 03 '19 at 17:48

2 Answers2

1

The problem is delay between the sendevent commands. If you check the sendevent source code, It is opening the file each time and write and then close. plus the delay between two adb shell commands. This makes continuous sendevent so slow and what you recorded is not getting replicated.

What you have to do is get the sendevent source code, modify it for taking as many as args it can and inside you open file once , parse 3 ints at a time and write until all args are parsed, close the file. You can see what you recorded is working like charm.

default sendevent

sendevent /dev/input/event1 3 47 0
sendevent /dev/input/event1 3 57 13578
sendevent /dev/input/event1 1 330 1
sendevent /dev/input/event1 1 325 1

Modified sendevent

/data/local/tmp/mysendevent /dev/input/event1 3 47 0 3 57 13578 1 330 1 1 325 1

I had done this same sometime back, you can refer full work here- https://github.com/rils/ARP/wiki

Rilwan
  • 2,251
  • 2
  • 19
  • 28
  • Thank you for your answer! But the timing was not the problem. I still send one command at a time but the order was not correct. See my answer for how it was solved. – C.M. Feb 06 '19 at 10:38
  • Ok, Nice. From your example in question I thought the decimal conversion is already taken care. – Rilwan Feb 06 '19 at 12:08
1

Yay - I finally figured out how to do it!

I wrote a little script which converts the adb shell getevent to decimal values and replaces the codes with known names from this article.

That gave me output like this:

/dev/input/event6: 3 - TRACKING_ID [4294967295]
/dev/input/event6: 0 - SYN_REPORT [0]
/dev/input/event6: 3 - 47 [0]
/dev/input/event6: 3 - POSITION_X [415]
/dev/input/event6: 3 - POSITION_Y [428]
/dev/input/event6: 3 - TOUCH_MAJOR [5]
/dev/input/event6: 3 - TRACKING_ID [0]
/dev/input/event6: 0 - SYN_REPORT [0]

Then I was able to figure out how the events worked and could replicate the behavior. I just needed to change the X and Y coordinates.

adb shell sendevent /dev/input/event6 3 57 88
adb shell sendevent /dev/input/event6 3 53 935
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6 3 48 5
adb shell sendevent /dev/input/event6 0 0 0
adb shell sendevent /dev/input/event6 3 53 906
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6 3 48 16
adb shell sendevent /dev/input/event6 0 0 0
adb shell sendevent /dev/input/event6 3 53 877
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6 3 48 16
adb shell sendevent /dev/input/event6 0 0 0
adb shell sendevent /dev/input/event6 3 53 847
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6 3 48 16
adb shell sendevent /dev/input/event6 0 0 0
adb shell sendevent /dev/input/event6 3 53 818
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6 3 48 16
adb shell sendevent /dev/input/event6 0 0 0
adb shell sendevent /dev/input/event6 3 53 789
adb shell sendevent /dev/input/event6 3 54 500
adb shell sendevent /dev/input/event6 3 48 16
adb shell sendevent /dev/input/event6 0 0 0
adb shell sendevent /dev/input/event6 3 57 -1
adb shell sendevent /dev/input/event6 0 0 0
C.M.
  • 713
  • 8
  • 18