3

I want to open a program and interact very briefly with the UI of it. For now I managed to open the program with this line:

subprocess.call([r"C:\Users\path\to\program\program.exe", "first-parameter", "second-parameter"])

The program displays at the start a small warning box with the button "Ok". I would like to simulate a key press "Enter" so that the program moves on. I tried to implement it like it was explained in in this question:

import subprocess
import win32com.client as comctl

wsh = comctl.Dispatch("WScript.Shell")

subprocess.call([r"C:\Users\path\to\program\program.exe", "first-parameter", "second-parameter"])
wsh.AppActivate("program.exe")
wsh.SendKeys("{Enter}") 

The SendKeys() argument was not reached until I closed the program.exe. After I closed the program.exe the "Enter" key got pressed.

Is there a way to interact with the UI of program.exe or do the KeyPress() so it gets reached?

1 Answer 1

1

To NOT wait for you program to exit you need to use subprocess.Popen instead of subprocess.call. More info in python docs here.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.