android - python 和 (android) adb shell

标签 android python shell cmd adb

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

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

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

最佳答案

应该这样做:

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

在您的原始脚本中:

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

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

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

关于android - python 和 (android) adb shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34120511/

相关文章:

Android - 带有简单字符串数组的 ActionBar SearchView 建议

python - pytest 无法导入通过 pip 安装且包含下划线的模块

python - 从 Python 列表中删除重复的整数序列

c - 如何在 if-else 语句中使用多个 execvp 调用?

linux - 条件循环中的多个读取命令是否会在 shell 脚本中产生问题

c - 将进程发送到后台并将控制权返回到我的 shell

android ExpandableListView - 将某些组设置为不可扩展

java - 如何在 OK-HTTP header 中添加非 ASCII 字符串?

android - 如何从android中的listView onItemClick获取项目?

python - 避免在 Python 中嵌套 for 循环