I’m attempting to write a Windows Form App that sends different keys to the active window after certain (non-regular) time intervals.
For example, after pressing a button, the program will wait 3 seconds, then send an “H” to the active window. After 1 more second, it sends an “E”, and after another second, it sends a “Y”.
But when I try this:
Thread.Sleep(3000);
SendKeys.Send("H");
Thread.Sleep(1000);
SendKeys.Send("E");
Thread.Sleep(1000);
SendKeys.Send("Y");
the program waits (at least) 3 seconds, but does not seem to pause between the next two keys sent.
I’ve been trying to implement something similar using a Timer since Sleep only guarantees a delay at least as long the argument given, and I need something more precise. However, the only examples I’ve been able to find had code executing after a regular time interval.
Is there a way to use a Timer to accomplish what I tried using Sleep, or a better method in general?
Use SendWait instead of Send.