1

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.

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I add an app using sendkeys, when I built it for the .net 2 framework it didn't work as expected (even though it didn't throw any error messages), but when I just changed the target framework to .net 4 it worked perfectly! isn't it amazing?
0

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.

2 Comments

Yes, I am using SendKeys.SendWait method only. Is there a way to specify the duration it has to wait
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.