Keyrepeat issues

Hello there.
This is my first time in the forums, so greetings!

I’m having some trouble handling inputs with SDL2 and I hope someone can help me figure it out.
I’m writing a cross-platform application in C and handle the keyboard with input event. Now, I know events are triggered by a key press, key release or an autorepeat keydown and that there should be only ONE keyup event per physical release of key. I’m also aware of the ‘repeat’ field which is set to non-zero when a keydown event was triggered by an autorepeat. The real issue comes right after that, apparently, my system is generating keydowns AND keyups by autorepeat, effectively resetting the ‘repeat’ field to zero and rendering it useless. For my application, it doesn’t really matter if a key is being held down at all, however, since I also get keyups by repetition, it’s impossible to differentiate between physical and automatic key presses and release.

I’m currently running 64bit Archlinux, I just tried the same code in a different computer with 32bit Windows 7 netbook and wasn’t able to reproduce the problem, so I’m not sure whether to think it’s some kind of issue with archlinux, linux in general or just my computer.

Just in case, something as simple as this will cause the issue for me:

Code:
#include <stdio.h>
#include <SDL2/SDL.h>

int main(void)
{
SDL_Event event;
int quit = 0;

SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindow("caption", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);

while (!quit)
{
	while (!quit && SDL_PollEvent(&event))
	{
		switch (event.type)
		{
		case SDL_KEYUP:
			if (!event.key.repeat)
				printf("KEYUP\n");
			break;

		case SDL_KEYDOWN:
			if (event.key.keysym.sym == SDLK_q)
			{
				quit = 1;
				break;
			}
			if (!event.key.repeat)
				printf("KEYDOWN\n");
			break;
		}
	}
}
SDL_Quit();
return 0;

}

If I held the ‘a’ key down, the output I’d get would be:
KEYDOWN
KEYUP
KEYDOWN
KEYUP
KEYDOWN
KEYUP

Thanks in advance for your help!

Ok, so I did a little more testing. I tried the same code in a 32bit Debian (virtual machine) and a 32bit Archlinux (different computer) and had no problems whatsoever… so this issue seems to be with this particular system. I don’t really think it being 64bits would change anything, but at this point I’m at a complete loss as of what to do.
I’ve read some posts where they talk about handling this within the Xserver, but that would defeat the whole purpose of portability I’m trying to achieve with SDL here.

I guess I could solve this with timers and such, but it really shouldn’t be that complicated…

After a couple of more tries I’m now guessing this might be some kind of bug with SDL2, I did two things:
(to differentiate the computers, the one I had the problem with will be my desktop PC and the other my netbook)

  1. Created a very very basic Archlinux live image with archiso. It only had the basic plus nvidia-drivers (intel for netbook), sdl2, xorg (server + utils) and xterm.
    Tried booting into it, both 32 and 64bit, with the desktop PC and had no luck whatsoever. After trying the 32bit in my netbook I almost got it working, when holding down a key, I would still get both DOWN and UP events but only a couple every 1 or 2 minutes (which is quite weird since it does work in the installed 32bit Arch), whereas the desktop PC prints them continuously.

  2. Same thing but with Debian wheezy, using debootstrap, for a 64bit Debian image. Netbook worked perfectly, not even those sporadic ones every couple of minutes, just great. Desktop PC still has the same problem.

I also booted into Windows XP 32bit in the desktop PC (I have it installed alongside Arch) and the code worked with no problems.

So I’m guessing there’s some weird bug or something with SDL2 plus certain hardware… and when in linux… ??

I have a related question. Is there a way to clear the event queue? It seems that events get queued up for far too long. Right now my game runs at about 60 fps (mostly due to using rendercopy but I am moving to opengl to hopefully speed things up). The main loops goes like this:

Draw->Get Inputs->Update Positions/do logic->Draw.

Keys seem to be stuck in the event queue for a few seconds after release.

Nevermind. I needed to add a while loop with SDL_PollEvent function like this:
while (SDL_PollEvent(event)){
…Input Proccessing…
}
I don’t really understand why though.