1 回答

TA貢獻1816條經驗 獲得超4個贊
您可以使用AutoIt來實現此目的。它具有 Python 綁定PyAutoIt。使用 PIP 安裝 PyAutoIt 后pip install PyAutoIt
,以下代碼即可完成您的工作。
import autoit
autoit.win_wait_active("Authentication Required") # title of the dialog box to wait. so it will wait for the Authentication Required dialog
autoit.send("username", 1) # second parameter is the mode (changes how "keys" is processed)
autoit.send("{TAB}") # press tab key to go to the password field
autoit.send("password", 1)
autoit.send("{Enter}") # press enter key
有關 send 方法中第二個參數的更多信息,這里是代碼,
def send(send_text, mode=0):
? ? """
? ? Sends simulated keystrokes to the active window.
? ? :param send_text:
? ? :param mode: Changes how "keys" is processed:
? ? ? ? flag = 0 (default), Text contains special characters like + and ! to
? ? ? ? ?indicate SHIFT and ALT key presses.
? ? ? ? flag = 1, keys are sent raw.
? ? :return:
? ? """
? ? AUTO_IT.AU3_Send(LPCWSTR(send_text), INT(mode))
添加回答
舉報