python 和 (android) 亚行 shell

python and (android) adb shell

我想通过计算机上的 python 代码使用 "adb shell tap x y" 函数(或您可能知道的任何其他方式)在我的 anroid phone 上模拟触摸。我试过使用

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

但它刚到达 "shell" 调用就卡住了。 (我知道 tap 功能有效,因为它适用于普通的 cmd window)

应该这样做:

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

在您的原始脚本中:

  1. 您在 Android 设备 (adb shell)
  2. 上启动了遥控器 shell
  3. 退出远程 shell 键入 exit 后,您在主机 shell (input tap 1400 800) 上发出命令。

相反,您应该使用 adb 将命令重定向到 Android 设备的远程 shell。为此,只需在 adb shell 之后附加命令,例如 adb shell input tap 1400 800。看看here.

我还删除了 adb kill-process 行,因为没有 kill-process adb 命令。