when you press a key it automatically delays a bit then starts repeating without delay.
the second key pressed action comes with a delay and i want it to start repeating without delay. and could not find anything useful.
i might not be able to tell what i want exactly. ok press simply a key and dont release it in a text editor. you will realize a delay at second character showing up
This is not an issue with SDL, but is how the OS reports keypresses to all applications. (The delay and fire rate are configurable in window's control panel somewhere).
The problem is that SDL keydown events are to indicate when the key is first pressed. They are not designed to tell you whether or not a key is currently being held down. For that you want to poll the realtime state of the key.
If you want the realtime state of the key, SDL offers a SDL_GetKeyState function:
1 2
Uint8 *keystate = SDL_GetKeyState(NULL);
if ( keystate[SDLK_RETURN] ) printf("Return Key currently being held.\n");
Alternatively, if you do not want to do that... you can catch the key_down and key_up events and have them set a bool to let you know the current key state.
EDIT: Ninja'd by James. I was unaware of that enable key repeat function. Though I admit I'm surprised it exists.
take that code out of your event loop/switch. The SDL_KEYDOWN event is only sent when the key is first pressed. It is not sent constantly.
So yes you are seeing delay here... not because SDL_GetKeyState has delay... but because your code is only running when SDL sends you a keydown event (which DOES have delay).
So yeah... you are not dealing with events here. You are just polling the key state. So take this out of your event loop.