I'm trying to develop a robust game input system with SDL 2.0.1. I want there to be no input lag at all.
I used to do this with SDL_GetKeyboardState()
, but I switched over to using SDL_Event
and SDL_PollEvent()
to have a uniform interface for Keyboard, Mouse and Joystick input (everything done with events).
This works fine, but if I want a continuous input when the key is held down (e.g. to move a character), there is a slight delay before SDL notices that the key is being repeated.
In SDL 1.2, it was possible to set this delay using a function call. Now it is no longer (as far as I'm aware).
How can I remove this delay? Should I switch back to reading the Keyboard state directly?
For reference, here is how I'm currently getting input...
SDL_Event sdlEvent;
while (running)
{
SDL_PollEvent(&sdlEvent);
switch (sdlEvent.type)
{
case SDL_QUIT:
running = false;
break;
case SDL_KEYDOWN:
printf("Key down!\n");
break;
default:
break;
}
}
The application prints "Key down!"
, then nothing for a small time (about a second), and then repeatedly prints until the key is released.
So how do I get rid of this delay?