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.

SendKeysTo Slow or Not Working Some of the Time

Keywords:     SendKeysTo 

Question:

I've developed a WinBatch program that takes a queue of information from an incoming text file, reads it one line at a time, then uses the information there to oversee its calculation in two programs. I have the code working fine for..well an indefinite amount of time...but i keep getting the same error, that it couldn't find a window with the title I'd specified in the SendKeysTo method.

With my latest run of this last night, I got the same message. Came in and an error window saying it couldn't find a window titled "~File Save". The rub is that the error window was sitting on top of the window I wanted it to see..."File Save"!.

The program found the file save window correctly 68 times before screwing up. Likewise, this problem occurs with other windows as well.

Answer:

The SendKey function tries *real hard* to make sure the application that it is going to send keys to is ready. It takes a lot of registry reading and a lot of disk access to be sure. After about 10 seconds or so it gives up and sends the keystrokes. (maybe)

Maybe it took the FileSave window 11 seconds to appear?

Try adding:

        WinWaitExist("~File Save",-1)

Related Question:

I'm using Winbatch 97D (+ Compiler) on Windows 95. I wrote a Winbatch program that will install an "Avery label Wizard for Word" on a Win95 PC. It basically sends keystrokes to the Windows as the appear "i.e. Install Avery Label Wizard in C:\program....- Yes?" I am using a series of WinWaitExist, Sendkeysto statements. Everything works fine until it gets to a particular Window. I have tried activating that Window first, then sending the keystrokes but nothing happens. The program doesn't freeze it just stops sending keystrokes. The window is activated but nothing else happens thru the Winbatch program. Any ideas on what could be causing this to occur?

Answer:

Try maybe disabling the "automatic sendkey delay" around that particular SendKeysTo with a:
        IntControl(43,0,0,0,0)
Re-enable it shortly thereafter with
        IntControl(43,1,0,0,0)

Syntax:

        IntControl(43, p1, 0, 0, 0) (32-bit only)

        Enable/disable "WaitForInputIdle".

        p1      Meaning
         0      Don't wait for application to be ready.
         1      Wait for application to be ready (default).
        -1      Don't change (just return current setting)

        This controls whether SendKey , SendKeysTo and SendKeysChild attempt to 
        wait until the active application is ready to accept input before sending 
        each keystroke. Returns the previous setting.

Another Case of Sendkeysto Slow:

In the following code:
   SendKeysTo("Cardfile","{f4}")
is what is hanging.

I tried the following also, which breaks it down and gives me 3 Sendkeys commands. It only is slow on the first SendKeys command. The other two are immediate.

   SendKeysTo("Cardfile","{alt}")
   SendKeysTo("Cardfile","s")
   SendKeysTo("Cardfile","g")

Answer:

I think some function is timing out (we try a lot of operations for 8 seconds before we give up and pretend it worked anyway). SendKey might be in this category.

If you can find the a SendKey statement that is hanging...

Add:

   IntControl(43,0,0,0,0)
before the statement and
   IntControl(43,1,0,0,0)
after it.

Try #1

   SendKeysTo("Cardfile","!sg")
Try #2
   IntControl(43,0,0,0,0)
   SendKeysTo("Cardfile","{alt}")
   SendKeysTo("Cardfile","s")
   SendKeysTo("Cardfile","g")
   IntControl(43,1,0,0,0)

Continued:

   >Try #1
   >SendKeysTo("Cardfile","!sg")
Still a 12 second delay
   >Try #2
   >IntControl(43,0,0,0,0)
   >SendKeysTo("Cardfile","{alt}")
   >SendKeysTo("Cardfile","s")
   >SendKeysTo("Cardfile","g")
   >IntControl(43,1,0,0,0)
Immediate response.

Article ID:   W13842
Filename:   Sendkeysto Slow or Not Working Sometimes.txt
File Created: 2001:01:05:13:30:08
Last Updated: 2001:01:05:13:30:08