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

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.

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

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.

Related

Fire double tap command to android device using adb

I have been trying to send a command to my device to double tap on the screen.
I tried to send this
adb shell input tap 600 1000
adb shell input tap 600 1000
However, it does not result into a doubletap.
Anyone willing to help me out?
This has worked for me pretty reliably until android 10; however, it no longer works on android 11 :(
I figured out a way to do it like this:
input tap <x> <y>&
sleep 0.1
input tap <x> <y>
as in
adb shell "input tap 520 1150& sleep 0.1; input tap 520 1150"
When digging around android 11 it seems that input command spawns up a JVM that is very slow, and it slowed down enough on android 11 to about 0.5 seconds, so the system does not recognize it as a double tap.
You can speed up the taps (or any user input) by including it in the same adb shell command. Previously I did this:
adb shell "input tap 520 1150; input tap 520 1150"
This will be easier on your system memory (as only one input command is executing at once) and may work pre android 11, but the one with & and explicit sleep between the two taps is what I switched to now.

How do root apps access the ui of other apps?

I am looking to build an app that (with root privileges) can access the ui on another app and click buttons on the screen. I have seen this done with many of the macro apps and some "bot" apps. I know they use the 'device administrator' and i have seen some that need the 'overlay over other apps' permission. I'm not looking for a comprehensive guide, and i know i would have to use some kind of ocr software to process the ui elements. Can someone give me some pointers? Example: https://forum.xda-developers.com/showthread.php?t=2241770
Thanks for any help!
Taine
I don't know how THEY do it, but one possible way is through the input shell command. I expect that normal programs don't have permission to use it, but adb shell does, and rooted programs presumably would. Usage is printed as follows:
Usage: input [<source>] <command> [<arg>...]
The sources are:
mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
touchscreen
gamepad
The commands and default sources are:
text <string> (Default: touchscreen) [delay]
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
You'd do something like
List<String> commandLine = Arrays.asList("input touchscreen swipe 500 10 500 500 100".split(" "));
Process process = Runtime.getRuntime().exec(commandLine);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
as mentioned in Any way to run shell commands on android programmatically? . (I've adapted it a bit, and haven't actually tested it, so it might take some fiddling.)
Note that it doesn't let you, e.g, see where buttons are, so you'll have to know what you're doing beforehand.
You might also try Instrumentation, as mentioned here: Android simulate key press

Log the Key Event when using Adb input

I use the command adb shell su -- getevent -lt /dev/input/event5 > Test.txt to log the touch event. It works when I touch the screen, i.e, it writes all actions (key down, key move and key up with the coordinates).
But, when I use the command adb shell input tap x y to simulate the touch, even if the device get the event (for example, the app is opened) but in the log file, there is no log lines about this tap.
How can I log the simulate the key event touch with adb?
The reason for you not being to see your input tap events in the getevent output is that sendevent and getevent work with Linux kernel input events and input command injects the events directly into the Android input event queue.
This (old but still useful) article has some nice diagrams illustrating the input event propagation in Android.
Unfortunately there is no easy (ready to use) way to do what you asked for. The closest thing I could think of is using dumpsys input command - it shows last 10 input events (including ones injected by the input command) in the RecentQueue: section.

how can i reduce the time lag to execute an adb shell command to perform swipe input on my android device

I want to input swipe commands back to back using a c program and adb shell to my android device .
But the lag between the commands is preventing me from achieving my goal.
Is there anyway to reduce this lag??
You can record some input and repeat it directly.
For example:
Record:
cat /dev/input/event0 > inputdata
Replay:
cat inputdata > /dev/input/event0
To find the correct event number you can use the getevent -p command.
There is no "lag between the commands". The input command is a java application and it takes about a second (depending on your device) to launch it. So you can not inject 2 events back to back faster than that.
You could either write your own input command which would accept multiple sets of coordinates in one take thus eliminating the need to run the command multiple times. Or you could use series of sendevent commands for emulating your gesture instead.

Send multi-touch events to Android emulator

I need to test an Android application that takes multi-touch input, such as pinch and rotate. I'd like to test this using the emulator if possible. Is there a way to send Linux input events, via ADB or otherwise, without modifying the Android source?
https://source.android.com/devices/tech/input/touch-devices.html
Events such as ABS_MT_POSITION_X, ABS_MT_POSITION_Y, and ABS_MT_TRACKING_ID.
Old question but still open.
Indeed there are options:
1.) Send commands via telnet (https://developer.android.com/studio/run/emulator-console)
2.) Use adb like (input tap X Y), e.g.
adb shell input tap 100 100

Categories

Resources