Yuval Eliav
Yuval Eliav

Reputation: 169

python and (android) adb shell

i would like to simulate touch on my anroid phone through a python code on my computer using the "adb shell tap x y" function (or any other way you may know). I have tried using

from subprocess import call
call(["adb", "kill-server"])
call(["adb", "shell"])
call(["input", "tap" , "1400" , "800"]) //example of x and y

but it just reaches the "shell" call and gets stuck. (I know the tap function works because it works on the ordinary cmd window)

Upvotes: 1

Views: 4325

Answers (1)

Gil Vegliach
Gil Vegliach

Reputation: 3562

This should do it:

from subprocess import call
call(["adb", "shell", "input", "tap" , "1400" , "800"])

In your original script:

  1. You start a remote shell on your Android device (adb shell)
  2. After you quit the remote shell typing exit, you issue a command on your host computer shell (input tap 1400 800).

Instead you should use adb to redirect a command to the Android device's remote shell. To do that, just append the command after adb shell, for example adb shell input tap 1400 800. Take a look here.

I also removed the adb kill-process line because there is no kill-process adb command.

Upvotes: 2

Related Questions