1
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ What if you print .key.repeat in both cases? \$\endgroup\$ May 27 '17 at 16:21
  • \$\begingroup\$ 0 for 2.0.4, and 1 for 2.0.5 first key press recorded, and 0 for second. What does this mean? \$\endgroup\$
    – jake
    May 27 '17 at 16:41
  • \$\begingroup\$ 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? \$\endgroup\$
    – jake
    May 27 '17 at 16:45
  • \$\begingroup\$ .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. \$\endgroup\$ May 27 '17 at 17:35
  • \$\begingroup\$ 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. \$\endgroup\$
    – jake
    May 27 '17 at 17:47
1
\$\begingroup\$

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.

It's possible that 2.0.5 behaves in the way described to make it easier to separately handle text and non-text input.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .