我想通过计算机上的 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"])
在您的原始脚本中:
- 您在 Android 设备上启动远程 shell (
adb shell
) - 在键入
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/