Question

When you hold down a key in a text editor, the character will appear, then you get a brief pause before a stream of characters appear. This is the system compensating for some people holding a key down longer than others / pausing in thought, etc.

My problem is that this is happening when I hold down a movement key in my SlimDX Direct3D11 application. Instead of moving the camera it moves 1 unit, pauses, and then moves fluidly.

I use the following code to capture keyboard data:

private void InitializeKeyboard()
{
    INPUT.Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, INPUT.DeviceFlags.None);
    INPUT.Device.KeyboardInput += new EventHandler<KeyboardInputEventArgs>(KeyboardInput);
}

void KeyboardInput(object sender, KeyboardInputEventArgs e)
{
    if (e.Key == Keys.W) camera.MoveForward(0.3f);
    if (e.Key == Keys.S) camera.MoveForward(-0.3f);
}

I use a similar system for capturing the mouse, and mouse movement works smoothly and responsively, so the problem must be in this automatic correction the keyboard is doing to prevent double taps. Does anybody know how to stop the hardware from doing that? Or if you're supposed to trap input differently in DirectX 11?

Was it helpful?

Solution

This is by design, you have SystemInformation.KeyboardDelay and KeyboardSpeed. The delay is the number of 250 msec that it will wait for the key starts repeating. It is normally longer than the speed, the delay between repeated key strokes.

Only use the keydown and keyup message. Get repetition from a timer or the natural way in which your game loop works. This also supports having multiple keys pressed, something else that doesn't work in your current approach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top