我使用pyautogui
编写了一个脚本,该脚本应该启动一个程序(IDE),然后开始使用它。 这是剧本至今:使用pyautogui自动化鼠标和键盘的更好方法
#! python3
# mouseNow.py - Displays the mouse cursor's current position.
import pyautogui, sys, subprocess
from time import sleep
x,y = 1100,550
subprocess.call([r'C:\...exe', arg1, arg2])
pyautogui.click(x,y)
sleep(5) # 2 sec should suffice but this is for safety
pyautogui.typewrite(my_string)
pyautogui.press('enter')
这工作很好,但我想成为便携。 x,y
值取决于我启动程序后程序提示出现在屏幕上的位置,但我认为这不是便携式。有没有办法将鼠标指向提示而不提供常量参数?像move_mouse_to_window_of_this_process_after_starting_it()
还有,我用sleep()
所以我想它出现后,将数据写入到窗口,但我想这不是一个很好的方式(一些PC将运行该慢得多,我猜),所以是有一种方法可以知道提示何时出现,然后执行pyautogui.typewrite(my_string)
?
编辑:我发现了move_mouse_to_window_of_this_process_after_starting_it()
一个简单的解决方案:
>>> pyautogui.hotkey('alt', 'tab')
是否有另一种与.exe文件交互的方式,不会排除替代? – CIsForCookies