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 7218735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:31:22+00:00 2026-05-28T21:31:22+00:00

I’m trying to capture keystrokes and replay them afterwards as equal as possible (time

  • 0

I’m trying to capture keystrokes and replay them afterwards as equal as possible (time critical).


What I tried so far:

First capture keys using SetWindowsHookEx (with WH_KEYBOARD_LL) and remember scan code and timestamp (milliseconds precision)

Then converting that raw data to predefined function calls (C#) after capture.
These are KeyUp and KeyDown methods implemented using SendInput with the known scan code (KEYEVENTF_SCANCODE in KEYBDINPUT struct)

I have concerns about the waiting part between these calls, though. Currently I’m using Thread.Sleep (single threaded replay application), but heard that would not be very precisely.


As I’m still asking here you’ll imagine that the current replay is not as exact as needed. It differs the same each time though!

Could I measure the overhead of my program (or of the single functions) and substract that each wait?
Should I try a different approach? Or is there a problem somewhere else in my thoughts?

(the program doesn’t need to be portable and can be tuned just for the dev computer)

  • 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-05-28T21:31:23+00:00Added an answer on May 28, 2026 at 9:31 pm

    Instead of using Thread.Sleep use a very tight loop and just continually check the time difference. You could even make it somewhat smart that for anything under a second, you just run in the tight loop and anything over a second you thread.sleep for 750ms and then check the difference and keep doing that until it is under a second.

    Maybe something like this, a class to hold your work items:

    public class workItem
    {
        public int offset { get; set; }
        public string name { get; set; }
    }
    

    Then use it like this:

    Queue<workItem> items = new Queue<workItem>();
    
    items.Enqueue(new workItem() { offset = 200, name = "A" });
    items.Enqueue(new workItem() { offset = 220, name = "B" });
    items.Enqueue(new workItem() { offset = 240, name = "C" });
    items.Enqueue(new workItem() { offset = 230, name = "D" });
    items.Enqueue(new workItem() { offset = 250, name = "E" });
    items.Enqueue(new workItem() { offset = 260, name = "F" });
    
    DateTime start = DateTime.Now;
    Debug.Print(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
    while (items.Count > 0)
    {
        var currItem = items.Dequeue();
    
        while (DateTime.Now < start.AddMilliseconds(currItem.offset))
        {
    
        }
        Debug.Print("{0}: {1}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), currItem.name);
    
    }
    

    It’s not perfect because there is time between when the while loop breaks and the debug fires, but it should get you pretty close. Some of the comments also had links that might be valuable (i.e. using a WaitOne or the parallel tasks)

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group

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.