增强对新打开应用程序中的回车键的模拟方法:Popen(*.exe)

2024-03-29 15:23:47 发布

您现在位置:Python中文网/ 问答频道 /正文

你好。当Popen调用时,我尝试在sqlservermgmtstudio中模拟Enter键ssms.exe我们失败了。我需要什么来编码?我显然是个Python新手。***目标是点击Enter,这样SSMS一旦启动就可以“连接”。如果需要,请查看屏幕截图。非常感谢。你知道吗

#! python3
from subprocess import Popen
import pyautogui
import time
import os
import signal

## 1. To open SSMS:
proc = Popen("C:\\Program Files (x86)\\Microsoft SQL Server\\130\\Tools\\Binn\\ManagementStudio\\Ssms.exe", shell=True)
print("After Popen")

proc.wait()
print("After wait")

focus = False
print("After focus")

while (focus == False):
    print("In While loop")
    focus = pyautogui.PAUSE = 1
    pyautogui.FAILSAFE = True
    pyautogui.press('enter')
    if (focus == True):
        break

Window Pop-up for SSMS


Tags: importfalsetrueprocexefocusprintpopen