WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Sending Keystrokes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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:

Use WinWaitExist or WinWaitClose to help with timing.
        ret = WinWaitExist("~Notepad", 10)
  		  if ret == 0 
		     Message("Notice", "The window was not found")
			  Exit
		  endif       

Or heres an example of a while loop checking for a window title:

        while WinExist("~Notepad")  
            timedelay(2)
        endwhile 
or to check for the window when it closes:
        while ! WinExist("~Notepad")  
            timedelay(2)
        endwhile
For 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:

  1. A window appears "Done":
             WinWaitExist("Done")
         ;or maybe
             WinWaitChild("MS Access","Done")
    
    or, something like:
                 while WinExist("Notepad")  
                   delay(2)
                 endwhile  
    
  2. 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
    
  3. 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:   W13824
Filename:   How to Make SendKey Wait .txt
File Created: 2008:04:10:14:34:40
Last Updated: 2008:04:10:14:34:40