Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:12:25+00:00 2026-06-03T06:12:25+00:00

I was wondering what the fastest way to send keystrokes using C# is. Currently

  • 0

I was wondering what the fastest way to send keystrokes using C# is. Currently I am using SendKeys.Send() and SendKeys.SendWait() with SendKeys.Flush().

I am using the following code to calculate the time of how long it takes for the both of them to work:

Stopwatch sw1 = new Stopwatch();
sw1.Start();
for (int a = 1; a <= 1000; a++)
{
    SendKeys.Send("a");
    SendKeys.Send("{ENTER}");
}
sw1.Stop();

And:

Stopwatch sw2 = new Stopwatch();
sw2.Start();
for (int b = 1; b <= 1000; b++)
{
    SendKeys.SendWait("b");
    SendKeys.SendWait("{ENTER}");
    SendKeys.Flush();
}
sw2.Stop();

The results of the 2 are:

Result 1: 40119 milliseconds
Result 2: 41882 milliseconds

Now if we put the SendKeys.Flush() on the second test, outside of the loop we get:

Result 3: 46278 milliseconds

I was wondering why these changes in the code make the speed very different.

I was also wondering if there is a faster way of sending many keystrokes, as my application does it a lot. (These tests were done on a really slow netbook)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:12:26+00:00Added an answer on June 3, 2026 at 6:12 am

    SendWait() is slower because it waits that the message has been processed by the target application. The Send() function instead doesn’t wait and returns as soon as possible. If the application is somehow busy the difference can be even much more evident.

    If you call Flush() you’ll stop your application to process all events related to the keyboard that are queued in the message queue. It doesn’t make too much sense if you sent them using SendWait() and you’ll slow down a lot the application because it’s inside the loop (imagine Flush() as a selective DoEvents() – yes with all its drawbacks – and it’s called by SendWait() itself too).

    If you’re interested about its performance (but they’ll always be limited to the speed at which your application can process the messages) please read this on MSDN. In sum, you can change the SendKeys class to use the SendInput function, rather than a journal hook. As quick reference, simply add this setting to your app.config file:

    <appSettings>
        <add key="SendKeys" value="SendInput"/>
    </appSettings>
    

    Anyway, the goal of the new implementation isn’t the speed but consistent behavior across different versions of Windows and and options (the increased performance is kind of a side effect, I guess).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering what is the fastest way that I can write some code. I
What's the fastest way to parse strings in C#? Currently I'm just using string
i was wondering - what's the fastest way to mail out from asp: i'm
just wondering:if I have two SortedDictionary objects, what is the fastest way to find
I was wondering which was the fastest way to apply a class on body
I am wondering what is the simplest and fastest way I can do authentication
I was wondering what the fastest way is to check for divisibility in VB.NET.
Perhaps I'm overlooking something obvious but I was wondering what the fastest way to
I was wondering what would be the fastest way to sort an array of
I'm looking for the fastest way to determine if a long value is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.