10

I'm trying to simulate 3 (simultaneous not consecutive) long taps on an android device using adb.

The most promising lead I found was here but I haven't been able to modify it so that I can use it.

Any thoughts on how to accomplish such feat?

Thanks.

Community
  • 1
  • 1
Iuli
  • 101
  • 1
  • 4
  • Has this thread not been resolved? It would help a lot for other users and myself if you marked a solved problem. If you have found a better solution, please share with the community. Thank you. – EyuelDK Apr 26 '17 at 04:17
  • I did manage to simulate a long tap with your response however, I did not manage to simulate 3 long taps at the same time. – Iuli Apr 27 '17 at 06:33
  • k thanks. I happened to be using this solution again and I was wondering if there was an improvement. – EyuelDK Apr 27 '17 at 12:13

2 Answers2

12

I found a very simple work around to simulate long touches. Simulate a swipe at the same point.

input swipe <x1> <y1> <x2> <y2> [duration in milliseconds]

Where x1 == x2, and y1 == y2.

This will simulate a swipe but since the your starting point and your end point are the same, it will act as if it was a lng press

EyuelDK
  • 3,029
  • 2
  • 19
  • 27
7

I've also been working on something related to this; and after loads of research, this is the best I've got - it can do exactly what you want, but there are a few drawbacks depending on your context.

It's simple, just send a low-level input events such as:

simulating a touch down event

sendevent /dev/input/event4 1 330 1         // touch down
sendevent /dev/input/event4 0 0 0           // end of report

Waiting after the touch down event is as if the user's finger is still on the device (i.e. a long press)

simulating a touch release event

sendevent /dev/input/event4 1 330 0         // touch release
sendevent /dev/input/event4 0 0 0           // end of report

SYNTAX

sendevent <device> <type> <code> <value> 

For better documentation of the arguments, refer to https://android.googlesource.com/platform/external/kernel-headers/+/8bc979c0f7b0b30b579b38712a091e7d2037c77e/original/uapi/linux/input.h

PROS:

  • I've found that using the sendevent command instead of the input command is significantly faster, most probably because you can send the specific low-level events you are interested in.
  • You have a lot of control over a device, such as, the touchscreen, keyboard, buttons, thermometer, and etc...

CONS:

  • You'll need to determine which device you are interested in manually. In my example I used /dev/input/event4, but don't rely that this is the same on your device. The devices differ from phone-to-phone, so you probably need to use the command getevent and then manually determine which device is your touchscreen. This can become a real pain especially if you are trying to programmatically determine the touchscreen device for any android phone, simply because even the device name technically might differ from phone-to-phone.

NOTE

If you are looking for a simpler way to send an tap, you can use the command

input tap <x> <y>

but be warned, you don't have the luxury of determining how long to simulate the press down (i.e. no long press possible)

Good luck.

EyuelDK
  • 3,029
  • 2
  • 19
  • 27
  • 1
    Thx for the infos! But, `getevent` requires root permissions, so this doesn't help on 99,9% of the devices. – k1ll3r8e Sep 06 '20 at 09:18
  • 1
    @k1ll3r8e Note that I used `sendevent` and did this on an UNrooted device. I'm unsure about the modern OS's version but it worked on the devices I had at the time. – EyuelDK Sep 06 '20 at 11:19