Fire a pinch in/out command to Android phone using adb
You can do it using adb getevent
and sendevent
.
Connect you device using adb
. Follow the steps below.
Identify your Input device:
Open any image on your device. To list input devices, run$ adb shell getevent
add device 1: /dev/input/event7
name: "msm8226-tapan9302-snd-card Headset Jack"
add device 2: /dev/input/event6
name: "msm8226-tapan9302-snd-card Button Jack"
add device 3: /dev/input/event2
name: "synaptics_dsx_i2c"
add device 4: /dev/input/event4
name: "qpnp_pon"Pinch in/out on the image, you should see some continuous logs like
/dev/input/event2: 0003 0030 00000005
/dev/input/event2: 0000 0000 00000000
/dev/input/event2: 0003 002f 00000000
/dev/input/event2: 0003 0036 00000144
/dev/input/event2: 0003 003a 00000079
/dev/input/event2: 0000 0000 00000000
/dev/input/event2: 0003 0036 00000142Confirms
/dev/input/event2
is the input device name for my target device.Get exact
getevent
and convertgetevent
tosendevent
:Make sure your screen switched on and is open with some image,
Run the below command on the prompt.$ adb shell getevent | grep dev/input/event2 > getevent_input.txt
While the above is running, Pinch in/out on the image on your phone.
Once completed, Kill the above command Ctrl + C
Open filegetevent_input.txt
and delete first line"add device X: /dev/input/eventX"
from it.Since
getevent
returns values in decimal, andsendevent
takes value in hexadecimal.
We have to do the above conversion.
This scripthex_to_dec.py
here does the Job. Thanks to this guy!$./hex_to_dec.py getevent_input.txt
Generates a file
getevent_input.scr
, Now rename this file to.sh
$ mv getevent_input.scr sendevent_input.sh
Open file
sendevent_input.sh
and delete second line"echoing – drawing function"
and save it.Run on device.
Transfersendevent_input.sh
to device.$ adb push sendevent_input.sh /sdcard/
1615 KB/s (64379 bytes in 0.038s)Make sure you device has an image open, and screen is not off.
$ adb shell sh /sdcard/sendevent_input.sh
Worked perfectly fine for me, If this what you looking for.
For visible results, enable Show touches
in Developer Options.
Environment: Motorola Moto G (Android 4.4.4)
with ADB (v 1.0.31)
on Ubuntu 12.04
.
How to make a double tap to expand the video screen using android adb commands
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"
Log the Key Event when using Adb input
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 Topics
How to Set Spinner Default Value to Null
Pick a Number and Name from Contacts List in Android App
Save State of Activity When Orientation Changes Android
Limit Scrolling and Zooming Google Maps Android API V2
Circular Dependencies Cannot Exist in Relativelayout, Android
Android Opengl Es 2.0 Emulator
I Have Forgotten My Keystore Password and I Want to Install My APK on Google Play. What Do I Do
Custom Layout for Spinner Item
Google Play App Description Formatting
Packaging Android Resource Files Within a Distributable Jar File
How to Get the Selected Item from Listview
Opening Webview Not in New Browser
Launch Android Application from a Browser Link
Project Has No Default.Properties File! Edit the Project Properties to Set One
Android Tabhost Change Text Color Style
Outlook - Read Another User's Calendar
Move Up Text View Only When Virtual Keyboard Open on Android