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.