Fire a pinch in/out command to Android phone using adb

前端 未结 2 825
小鲜肉
小鲜肉 2020-11-28 11:31

So far I\'m able to tap, swipe, unlock, install/uninstall and launch app using adb commands but not able to find how to perform zoom in/out using adb command.

I have

相关标签:
2条回答
  • 2020-11-28 12:06

    A (kind of hacky) solution with adb shell input looks like

    adb shell input tap 200 200 & PIDTAP=$!
    sleep 0.1
    adb shell input swipe 200 200 200 100 1000 & PIDSWIPE=$!
    wait $PIDTAP
    wait $PIDSWIPE
    

    The idea is that we launch TAP command, then short sleep and then perform SWIPE. Such commands sequence is interpreted as tap + swipe hence zoom is performed. The example above would be a zoom out on a map.

    0 讨论(0)
  • 2020-11-28 12:14

    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.

    0 讨论(0)
提交回复
热议问题