我使用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