How to Make a SendKey Wait
Keywords: process control sendkey wait pacing problem
Question:
How do I make sendkey wait for my application?Answer:
WinBatch is a linear language, it steps thru the commands 1,2,3 and does not wait for applications to finish there processing before sending the next keystroke. You must built in the delay.The options for creating a pause or delay are:
Here's an example of a while loop checking for a window title:
- Use the TimeDelay command. However, the time interval must be specified.
- Use IntControl 36 (available only in 32-bit versions).
- Learn something about the application which is trackable, ie. a dialog box is displayed when printing. Write a Loop in the script which checks for the existence of the dialog box. When the dialog box is no longer there the script will continue.
Things you can check for: files that exist, windows, dialog boxes, system resource percents etc. What does it do? Make a file on disk (FileExist)? Update a file (FileTimeCode)? Make any registry entries (regqueryvalue)?
while WinExist("Notepad") timedelay(2) endwhileor to check for the window when it closes:while ! WinExist("Notepad") timedelay(2) endwhileFor example, a dialog box may be displayed when printing is in progress. Write a loop in the script which checks for the existence of the dialog box. When the dialog box closes, the script will continue.The idea is to figure out some way of telling when an application is done. Does anything on the screen change. Did some file suddenly appear? You need something you can get your hands on. For example:
- A window appears "Done":
WinWaitExist("Done") ;or maybe WinWaitChild("MS Access","Done")or, something like:while WinExist("Notepad") delay(2) endwhile- You can do a "FileExist" on the file until it appears, and then do a FileSize on it till there is a non-zero file size. That generally indicates completion.
fname="c:\xxx\output.txt" while !FileExist(fname) TimeDelay(1) endwhile while FileSize(fname)==0 TImeDelay(1) endwhile- Windows on the screen change:
This handy script helps you see what is going on, in terms of parent and child window names:
parents=WinItemize() thisone=AskItemList("Choose a Parent Window",parents,@tab,@sorted,@single) children=WinItemChild(thisone) child=AskItemList("Children of %thisone%",children,@tab,@sorted,@single)The WinItemChild() along with a strindex might be most helpful.
Article ID: W13824Filename: How to Make SendKey Wait .txt