Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在python中使用adb sendevent_Android_Python_Adb - Fatal编程技术网

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
命令?

  • sendevent
    接受4个参数
  • Popen
    args
    应为
    ['adb',
    “shell”、“sendevent/dev/input/eventX类型代码值”]
    -不要拆分远程命令
  • 计时对于
    sendevent
    序列很重要,
    adb shell
    调用本身有点昂贵,因此在设备上使用shell脚本效果更好
  • 注意shell脚本中的换行符-确保它是unix样式(单个
    \n
    而不是
    \r\n