I'm using the following code to send keystrokes to an application:
import win32com.client
import time
process_id = 2032 # I change this value if needed
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate(process_id)
shell.SendKeys('^o')
time.sleep(.5)
# more input ...
The problem is: at some point everything goes downhill, meaning: the application is hanging (unpredictable for how long and when!) for whatever reason with unpleasant consequences. For example instead of clicking the "OK" button via the {ENTER} command, that keystroke does something else. After that all the keystrokes mess things up because they do not do what they were intended to do. Is there a difference between using time.sleep and win32api.sleep by the way? And is there a systematic way to check whether the application that I'm sending the keystrokes to, is in a stable ready-state again?
time.sleepandwin32api.sleepare the same, except thattime.sleepis in seconds andwin32api.sleepis in milliseconds.