Ok so I am running tests in WatiN and I am using the SendKeys method. According to the MSDN website I can enter:
System.Windows.Forms.SendKeys.SendWait("{LEFT 2}");
And this will enter left two times. This however does not work, I believe because the application needs time between each keypress. I order to do what I need the program to do I used Thread.Sleep between each keypress to ensure they were getting read. Is there a more efficient/proper way to do this? This is my current method code:
System.Windows.Forms.SendKeys.SendWait("{LEFT}");
Thread.Sleep(500);
System.Windows.Forms.SendKeys.SendWait("{LEFT}");
Thread.Sleep(500);
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
Unfortunately, I don't believe there is. According to MSDN there are timing issues with SendKeys:
The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds.
The SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation.
As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWait method will not wait for messages to be processed when they are sent to another process. If your application relies on consistent behavior regardless of the operating system, you can force the SendKeys class to use the new implementation by adding the following application setting to your app.config file.
<appSettings>
<add key="SendKeys" value="SendInput"/>
</appSettings>
To force the SendKeys class to use the previous implementation, use the value "JournalHook" instead.
You could try changing between implementations to see if there is a change in your results.
Alternately, according to this post just using Thread.Sleep(0);
after your input should work. Not the most elegant solution but if it works it would be faster than a 500ms pause.