0

我有一个带有以下部分的python脚本:

for index in range(1,10):
   os.system('./test')
   os.system('xdotool key Return') 

我想要做的是运行可执行文件 ./test,它会打开一个 QtGUI。在这个 GUI 中,会出现一个按键提示按钮。我想自动化 GUI 的这个按键,以便可执行文件继续。

我的 python 脚本虽然运行了可执行文件,但出现了 GUI 提示,并且直到可执行文件之后才输入按键。有没有什么办法解决这一问题?

4

2 回答 2

0

请尝试Pyautogui以编程方式控制鼠标和键盘

点安装 PyAutoGUI

您可以在此处找到更多详细信息: https ://pyautogui.readthedocs.io/en/latest/quickstart.html#mouse-functions

您还可以使用ClointFusion,它是使用 Pyautogui 在其他软件包中开发的。有关 ClointFusion 的更多详细信息,请参阅存储库: https ://github.com/ClointFusion/ClointFusion#readme

免责声明:我是 ClointFusion 的开发者之一

于 2021-11-04T19:06:34.047 回答
0

os.system在子进程退出之前不会返回。你需要subprocess.Popen. 在发送击键之前一段时间也是一个好主意sleep(子进程可能需要一些时间才能准备好接受用户输入):

from subprocess import Popen
from time import sleep

for index in range(1,10):
   # start the child
   process = Popen('./test')
   # sleep to allow the child to draw its buttons
   sleep(.333)
   # send the keystroke
   os.system('xdotool key Return')
   # wait till the child exits
   process.wait()

我不确定您是否需要最后一行。如果所有9个子进程都应该保持活动状态 - 将其删除。

于 2016-08-29T11:01:54.600 回答