How to prevent the KeyDown event delay?

I'm currently trying to design a simple 3D engine that will run in a window so I'm using windows forms and not the DXUT.

I'm trying to get keyboard input working to move my camera and although the following code gets seems to do the job it has an annoying delay if you hold down the button. It moves as soon as pressed but then there is a delay before it continues moving... I don't want this delay however.

Here is the code i'm using.

 

this.KeyDown += new KeyEventHandler(OnKeyPressed);

...

private void OnKeyPressed(object sender, KeyEventArgs e)

{

switch(e.KeyCode)

{

case Keys.F1:

isShowFPS = !isShowFPS;

break;

case Keys.W:

MyCamera.position.Z += 0.2f;

break;

}

}

Crude camera moving code aside (i intend to change that later), how  to i stop this delay.

I realise the DXUT framework doesn't have this problem but I don't quite understand the method it uses for keyboard input, I don't quite understand WndProc or what ever it is, and how it works. I've googled a lot for it but still haven't really found a simple solution. If anyone can explain how the DXUT framework handles keyboard input or knows of a good tutorial for teaching keyboard input I would be very greatful.



Answer this question

How to prevent the KeyDown event delay?

  • jankowiak

    Okay I solved it by just using DirectInput.

    DirectInput wasn't as hard as I thought.


  • How to prevent the KeyDown event delay?