0

I want to write a programm which measures the time between two keyboard events,to determine whether it's a normal guy typing or something like keystroke injection

I know how to measure the time (StopWatch class), i just dont know how to observe keyboard inputs

    {
        Stopwatch sw = new Stopwatch();

        try
        {
            if (e.RoutedEvent == Keyboard.KeyDownEvent)
            {
                sw.Start();
                PrevTime = CurrentTime;
            }
            else  
            {
                sw.Stop();
                CurrentTime = sw.ElapsedMilliseconds;
            }

How do i get the events i want in e ?

  • Possible duplicate of [Capture any kind of keystrokes (aka keylogger), preferably c# .net but any kind will do](https://stackoverflow.com/questions/6465526/capture-any-kind-of-keystrokes-aka-keylogger-preferably-c-sharp-net-but-any) – Kami Feb 14 '19 at 12:43

1 Answers1

-1

Create two DateTime object as a DateTime.Now() and then subtract one from another and the difference will be your result of how much time passed between those events.

  • 1. DateTime.Now() is not precise enough for my purposes 2. i dont know how to get keyboard events ? – Colin1860 Feb 14 '19 at 12:45
  • The precision reach miliseconds so it should be precise enough. You can try it with https://learn.microsoft.com/en-us/dotnet/api/system.timespan?view=netframework-4.7.2 if you dont want tu use DateTime.Now() For the key events see this. you have a list of keycode and their status when you want to call the event https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.keyeventargs.keycode?view=netframework-4.7.2 – Aleksander Zawisza Feb 14 '19 at 12:50