Android 在python中使用adb sendevent
我遇到了一个奇怪的问题,从命令行运行Android 在python中使用adb sendevent,android,python,adb,Android,Python,Adb,我遇到了一个奇怪的问题,从命令行运行adb shell sendevent x命令可以正常工作,但是当我使用以下任何一种命令时: subprocess.Popen(['adb','shell','sendevent','x','x','x']) subprocess.Popen('adb shell sendevent x',shell=True) subprocess.call(['adb','shell','sendevent','x','x','x']) 它们都失败了——即使在shell脚
adb shell sendevent x
命令可以正常工作,但是当我使用以下任何一种命令时:
subprocess.Popen(['adb','shell','sendevent','x','x','x'])
subprocess.Popen('adb shell sendevent x',shell=True)
subprocess.call(['adb','shell','sendevent','x','x','x'])
它们都失败了——即使在shell脚本中工作的模拟触摸在通过python调用时也不能正常工作。此外,我还尝试了将shell脚本推送到设备上,并使用adb shell/system/sh/sdcard/script.sh
成功地运行了它,但当我尝试通过python运行该命令行时,脚本失败了
更奇怪的是,脚本在运行,但例如,它似乎没有在脚本执行一半时执行命令sleep 1
,echo
命令起作用,sendevent
命令似乎不起作用
似乎都不可能,但确实如此。如何通过python运行一组adb shell sendevent x
命令?
接受4个参数sendevent
的Popen
应为args
-不要拆分远程命令['adb', “shell”、“sendevent/dev/input/eventX类型代码值”]
- 计时对于
序列很重要,sendevent
调用本身有点昂贵,因此在设备上使用shell脚本效果更好adb shell
- 注意shell脚本中的换行符-确保它是unix样式(单个
而不是\n
)\r\n