You are not logged in.

#1 2014-07-23 01:38:40

elpatolocosisi
Member
Registered: 2014-07-23
Posts: 2

Keyrepeat issues

Hello there!
I hope someone can help me out with this, I'm not entirely sure if this should be posted here, but it seemed like the most reasonable place. I'm running 64bit Arch.

I'm writing a cross-platform application in C, using SDL2 for a basic interface. Now, I haven't tried this with another library but I think the issue is not within the SDL library.
I'm handling the input interface with events and should take notice of key's being held down. For those not acquainted with SDL2's keyboard events, when a key is held down you will keep receiving a keydown event (rate determined by OS, xset for instance) but only ONE keyup event when the key is physically released. However, instead of that one unique keyup event, I keep receiving them alongside the keydown events, this makes it impossible to differentiate between keydown events triggered by autorepeat of keys and those by physical key presses.

First off, SDL2 has a structure member (repeat) used to determine whether a key press was generated by an autorepeat (when non-zero). That is of no use here since keyup events are passed repeatedly as well, effectively resetting the 'repeat' member to cero.
Secondly, I've tried the same code on a different computer with both Windows 7 and 32bit Arch and cannot reproduce the problem, I've also tried the same code on 32bit Debian in a virtual machine and it works just fine there. I don't really think word length has anything to do with this, but it doesn't hurt to mention.

Given those two reason, I think the problem isn't related to the SDL2 library but to something with this system. I'm not sure what to check or what to do to figure this out. I tried disabling autorepeat with xset to see if I could at least stop it altogether, however it is re-enabled by the application itself (probably by SDL2).

I'd really appreciate some help, if I'm at the incorrect place for this kind of questions please let me know. If any kind of system information is needed I'll gladly provide it.

Offline

#2 2014-07-24 16:57:54

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Keyrepeat issues

Can you please post the example code (and the command you use to compile it) so we can try it?

Offline

#3 2014-07-24 17:57:56

elpatolocosisi
Member
Registered: 2014-07-23
Posts: 2

Re: Keyrepeat issues

Yes, of course.
I've been using this very simple piece of code to test this:

#include <stdio.h>
#include <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;
}

which I compile with:

gcc -ansi -Wall -pedantic `sdl2-config --cflags --libs` main.c

If I hold down the 'a' key for instance, the output I get is:
KEYDOWN
KEYUP
KEYDOWN
KEYUP
....

If you remove the "if (!event.key.repeat)" condition, the output expected would be many KEYDOWNs and only one KEYUP when physically releasing the 'a' key, however, I get both type of events while it's being held down.

I've been looking around for information about what X does with the inputs... as far as I can see (both with xev and implementing a very simple C app with Xlib), this kind of behavior is to be expected, am I right? I'm guessing that because they behave identically in the different systems I've tried. If that's the case, then this could be a bug with SDL2, however I'm not too sure about that and I have no way of reproducing this in any other system. I'll try booting another 64bit Arch with openbox in a live CD and see what happens there.

Thanks for your help!

Offline

Board footer

Powered by FluxBB