I also worked on something related to this; and after loads of research, this is the best I have - it can do exactly what you want, but there are several drawbacks depending on your context.
It's simple, just send low-level input events like:
simulating touch down event
sendevent /dev/input/event4 1 330 1 // touch down sendevent /dev/input/event4 0 0 0 // end of report
Waiting after a touch event as if the user's finger is still on the device (i.e. long press)
Sensory Release Event Modeling
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 a better documentation on arguments, refer to https://android.googlesource.com/platform/external/kernel-headers/+/8bc979c0f7b0b30b579b38712a091e7d2037c77e/original/uapi/linux/input.h
PROS:
- I found that using the sendevent command instead of the input command is much faster, most likely because you can send events of interest to you at a certain level.
- You have great control over the device, for example, the touch screen, keyboard, buttons, thermometer, etc.
MINUSES:
- You will need to determine which device you are interested in manually. In my example, I used / dev / input / event 4, but I don't rely on the same thing on your device. Devices differ from phone to phone, so you probably need to use the getevent command and then manually determine which device is your touch screen. This can be a real pain, especially if you are trying to programmatically identify the touch device for any Android phone, simply because even the name of the device can technically differ from phone to phone.
Note
If you are looking for an easier way to send a tap, you can use the command
input tap <x> <y>
but be careful, you have no way to determine how long to simulate a click (i.e., a long press is not possible)
Good luck.
source share