Long delay between two consecutive KeyDown events

I’m kind of writing a small game engine - to understand how they work from the inside out. I currently do not want to interfere with OpenGL or DirectX, so I stick to drawing on the control with GDI + and all this WinForms stuff.

Obviously, I need to process the input. More specifically, keyboard events. This, however, creates a problem:

protected override void OnKeyDown(KeyEventArgs e)
{
    Trace.WriteLine(string.Format("KD {0:hh:MM:ss.fff} {1}", 
        DateTime.Now, e.KeyCode));
}

This code (even with the shortest retry delay set in the keyboard applet on the control panel) gives the following:

KD 10:02:18.318 Right
KD 10:02:18.570 Right
KD 10:02:18.598 Right
KD 10:02:18.639 Right
KD 10:02:18.667 Right
KD 10:02:18.701 Right

As you can see, there is 0.25 sec. the delay between the first two events. This leads to slow movements of objects on the screen, obviously: at first it moves slightly to the right, then it stops for a noticeable moment, and then continues.

? WinForms, DirectInput ( - kosher way nowadays?)?

+3
1

Windows - .
WinForms, , .

DirectInput (v7) , .
, GetKeyboardState GetAsyncKeyState .

+3

Source: https://habr.com/ru/post/1734517/


All Articles