SDL2.0.5 - SDL_KEYDOWN shows two identicle presses when only one key is pressed

SDL2.0.4 using this code:

SDL_Keycode key = 0;

while(SDL_PollEvent(&(Global->event)) != 0)
{
if(Global->event.type == SDL_QUIT)
{
/* Allow users to exit the game */
break;
}
else if(Global->event.type == SDL_KEYDOWN)
{
/* Actual Keypresses */
key = Global->event.key.keysym.sym;

if(key == getSDLKValue("p-key"))
{
/* ... p key is pressed */
}
else if(key == getSDLKValue("q-key"))
{
/* ... q key is pressed*/
}
}
}


Works fine to get a single p key press when the key is pressed down. However, when manually compiling, and using 2.0.5 logging shows that a single key press has:

Key pressed: 112
Key pressed: 112


It gets pressed twice in the window, when only once in reality.

Is this a bug with SDL2.0.5? Running on Ubuntu 16.04, manually compiled SDL2.0.5.

• What if you print .key.repeat in both cases? – HolyBlackCat May 27 '17 at 16:21
• 0 for 2.0.4, and 1 for 2.0.5 first key press recorded, and 0 for second. What does this mean? – jake May 27 '17 at 16:41
• I think stackoverflow.com/a/27084554/5698848 will solve my problem, but I'm really curious why 2.0.4 -> 2.0.5 adds this "repeat" and what it is? Compiling it manually (2.0.5) vs a package manager (2.0.4) might have some make flags I didn't enable? – jake May 27 '17 at 16:45
• .repeat is meant to be used mostly for text input. Try to hold a button and after a moment you will start to receive a lot of "fake" keypresses with .repeat == 1. I don't think there are special flags to change the behaviour you're seeing. Something tells me that it's a small design decision. – HolyBlackCat May 27 '17 at 17:35
• I see. You can make your and my comments the post Answer if you want and I can accept, or I will do so in a few days. – jake May 27 '17 at 17:47

event.key.repeat is 0 for actual key presses, and 1 for fake presses (which are generated if you hold a button long enough).
To fix this issue, this question suggests to just check if event.key.repeat == 0.