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.

Leave a Comment