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.
Related
I have a large set of devices that I want to add google accounts to. The google accounts are already setup so I just want to add these existing accounts to the devices through a command line script.
There are two possible ways (Non-Root):
#1 Develop an app that implements the Account Manager and facilates the login process.
#2 Use a series of ADB commands to pass the input strings and stimulate the touch events.
ADB Command Example:
Start the native add account settings screen
ADB shell am start -a android.settings.ADD_ACCOUNT_SETTINGS \
-n com.android.settings/.accounts.AddAccountSettings
Select the absolute coordinates of the screen where the Google account is located. Each device has different screen sizes, so you have to figure out the exact position of your device. If you have multiple apps with login accounts they will also appear here. E.g., Microsoft Office, Reddit, and WhatsApp.
adb shell input tap X Y
Tips: You can enable the Show taps and Pointer location from
Developer Option. This will give you the precious location of the
touch input.
Set the desired input text
adb shell input text "account#gmail.com"
If you want select a keyboard event, pass the event code from the KeyEvent constants
adb shell input keyevent 66
Here, 66 is the event code of "KEYCODE_ENTER"
Repeat the input/touch process until you successfully login to the system.
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.
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.
I am trying to analyze a streaming video in my Android device. I want everything automated by scripts, because the device has to repeat the test a lot of times and I want to do it remotely (it is LAN connected). For that, I am using a special app, which starts to stream the video on a small-sized screen (it is special for that, I must expand the screen and I must use only this android app). A double-tap should be made to expand the screen (there is no button to expand, I can do it only double-tapping manually).
Due to my automation, I am trying to expand the video screen from a batch file when the video is streaming executing the following:
adb shell input tap x1 y1
adb shell input tap x1 y1
But it does not work. I've tried also with input touchscreen, input swipe x1 y1 x1 y1, I put every combination in a infinite loop, and it never expands. Maybe because the double tap it is too slow.... or maybe because that event needs to send a tap-release event.
Anybody encountered this problem already? How could I do a double tap to expand the screen remotely?
Thank you for your time!
Finally I got it. First I've recorded the double-tap event and stored it into a binary file:
adb shell
cd /sdcard/
cat /dev/input/event_X > doubletap
Do the doubletap wherever you want it, and then, end the recording with CTRL+C
The event_X is the event called sec_touchscreen.
It can be got from:
adb shell getevent -p
Then, you can replay the doubletap with:
adb shell "cat /sdcard/doubletap > /dev/input/event_X"
In my case, it was tricky because it did not work executing once the replay, but two, like:
adb shell "cat /mnt/sdcard/doubletap > /dev/input/event_X"
adb shell "cat /mnt/sdcard/doubletap > /dev/input/event_X"
I am trying to send touch events to a device using AndroidDebugBridge, so that I can do some basic automation for UI tests. I have followed the discussion in LINK. I am able to use sendevent to simulate touch on emulators, but unable to do the same on a device.
Like in above link the emulator seems to send out 6 events for each touch ( xcoord, ycoord, 2 for press,2 for release) and it was easy to use this information to sendevents, but a getevent for the touchscreen for a device seems to generate far too many events.
Has somebody managed to send touch from ADB to a device? Could you please share the solution.
Android comes with an input command-line tool that can simulate miscellaneous input events. To simulate tapping, it's:
input tap x y
You can use the adb shell ( > 2.3.5) to run the command remotely:
adb shell input tap x y
In order to do a particular action (for example to open the web browser), you need to first figure out where to tap. To do that, you can first run:
adb shell getevent -l
Once you press on the device, at the location that you want, you will see this output:
<...>
/dev/input/event3: EV_KEY BTN_TOUCH DOWN
/dev/input/event3: EV_ABS ABS_MT_POSITION_X 000002f5
/dev/input/event3: EV_ABS ABS_MT_POSITION_Y 0000069e
adb is telling you that a key was pressed (button down) at position 2f5, 69e in hex which is 757 and 1694 in decimal.
If you now want to generate the same event, you can use the input tap command at the same position:
adb shell input tap 757 1694
More info can be found at:
https://source.android.com/devices/input/touch-devices.html
http://source.android.com/devices/input/getevent.html
2.3.5 did not have input tap, just input keyevent and input text
You can use the monkeyrunner for it: (this is a copy of the answer at https://stackoverflow.com/a/18959385/1587329):
You might want to use monkeyrunner like this:
$ monkeyrunner
>>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
>>> device = MonkeyRunner.waitForConnection()
>>> device.touch(200, 400, MonkeyDevice.DOWN_AND_UP)
You can also do a drag, start activies etc.
Have a look at the api for MonkeyDevice.
You don't need to use
adb shell getevent -l
command, you just need to enable in Developer Options on the device [Show Touch data] to get X and Y.
Some more information can be found in my article here: https://mobileqablog.wordpress.com/2016/08/20/android-automatic-touchscreen-taps-adb-shell-input-touchscreen-tap/
Building on top of Tomas's answer, this is the best approach of finding the location tap position as an integer I found:
adb shell getevent -l | grep ABS_MT_POSITION --line-buffered | awk '{a = substr($0,54,8); sub(/^0+/, "", a); b = sprintf("0x%s",a); printf("%d\n",strtonum(b))}'
Use adb shell getevent -l to get a list of events, the using grep for ABS_MT_POSITION (gets the line with touch events in hex) and finally use awk to get the relevant hex values, strip them of zeros and convert hex to integer. This continuously prints the x and y coordinates in the terminal only when you press on the device.
You can then use this adb shell command to send the command:
adb shell input tap x y
Consider using Android's uiautomator, with adb shell uiautomator [...] or directly using the .jar that comes with the SDK.