Fire a Pinch In/Out Command to Android Phone Using Adb

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.

  1. 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 00000142

    Confirms /dev/input/event2 is the input device name for my target device.

  2. Get exact getevent and convert getevent to sendevent:

    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 file getevent_input.txt and delete first line "add device X: /dev/input/eventX" from it.

    Since getevent returns values in decimal, and sendevent takes value in hexadecimal.

    We have to do the above conversion.

    This script hex_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.

  3. Run on device.
    Transfer sendevent_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



Leave a reply



Submit