AndB
AndB

Reputation: 139

How do I create a delay between SendKeys.Send C#

Obviously this doesn't work correctly. I want to use C# and not AutoIt. What could make this work better?

{
     Process.Start("iexplore.exe");
     System.Threading.Thread.Sleep(1000);
     SendKeys.Send("{F6}" + "http://google.com/" + "{Enter}");
     System.Threading.Thread.Sleep(1000);

     int counter = 1;
     while ( counter <= 10 )
     SendKeys.Send("{RIGHT}" + "{SUBTRACT}");
     counter = counter + 1;
}

Upvotes: 2

Views: 1232

Answers (2)

New Developer
New Developer

Reputation: 3305

Use SendWait() insted of Send(). That will fix the issue.

Upvotes: 1

Max
Max

Reputation: 4077

I might be missing something here but if it is C# and if you have the following statement :-

while(count <=10)
SendKeys.Send (....)

wouldn't that be an infinite loop since the increment statement for counter is not present within the block of the while loop?

For the delay, try using the following :-

while(counter <= 10)
{
   SendKeys.Send("{RIGHT}" + "{SUBTRACT}");
   counter = counter + 1;
   System.Threading.Thread.Sleep(1000);
}

The above answer is assuming that you want the current thread to block and that there is no other processing being done in the while loop

Upvotes: 2

Related Questions