Iuli
Iuli

Reputation: 101

Can I use adb to simulate 3 long taps on a device?

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.

Upvotes: 10

Views: 8102

Answers (2)

EyuelDK
EyuelDK

Reputation: 3199

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

Upvotes: 13

EyuelDK
EyuelDK

Reputation: 3199

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.

Upvotes: 7

Related Questions