Reputation: 9022
I am trying to write an WinForms application which simulate keyboard button clicks.I tried SendKeys.Send()/SendWait(), but, it leads to infinite loop.I tried to sleep the thread for 5 sec., but, it looped with interval of 5 sec.
private void button1_Click(object sender, EventArgs e)
{
SendKeys.SendWait("Hi {Enter}");
Thread.Sleep(5000);
}
Upvotes: 0
Views: 219
Reputation: 11196
Apparently your button1
has the focus after being clicked. Now sending Enter
presses the button another time. To solve that you need to set the focus before sending keys to wherever your keys should go to (another app, another control).
Upvotes: 1