tags:

views:

63

answers:

2

I have a windows application, where I am using send keys to navigate from one window to another. My send key sequence is like activating another window with in my app, and sending key strokes to that window. But the key strokes I am sending is getting updated in the same window where I am activating the other window.

But after few key strokes it is going to the other window. Seems like synchonization issue with send keys. Is there a way to specify the operation of the current send key is finished, before sending the next sendkey.

A: 

Have you tried using SendKeys.SendWait. This will wait until the key was sent and the action processed before carying on.

Since the windows are in your own application, why not provide set of functions to carry out the actions rather than using SendKeys. Functions can create the window once the windows in created and active which you can detect by handling the Activated event, you can then use SendKeys to send key strokes to the new window, if you really need to, otherwise again have functions on the window class that you can call to carry out the operations that the key strokes would induce. You could probably define a common interface that your windows implement to facilitate this interaction.

Chris Taylor
Yes, I am using SendKeys.SendWait method only. Is there a way to specify the duration it has to wait
AvidProgrammer
try the flush method
zapping
@zapping, that is exactly what SendWait does, it posts the key and then calls Flush. Calling flush a second time might or might not work depending on timing, which is always risky to rely on.@AvidProgrammer, I guess the problem then is that the actions taken when the keys are being sent are completed probably by using PostMessages internall which basically posts a message and returns immediately therefore making SendWait useless. It would be terrible in my IMHO to artifically sleep between calls.
Chris Taylor
A: 

I have found sendkeys to be nothing but unreliable. Try the input simulator instead.

Eyvind