We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3477

Summary: Keys send two keydown events at once
Product: SDL Reporter: Marisa <saniukeokusainaya>
Component: eventsAssignee: Alex Baines <alex>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.5   
Hardware: x86_64   
OS: Linux   
Attachments: skip resent filtered keys
don't skip sending text for resent events

Description Marisa 2016-10-31 18:11:06 UTC
I have noticed this after updating from 2.0.4 on my system (Arch Linux). In many games, or even in simple programs I could write by myself, pressing any key results in two keydown events being sent at the same time.
Comment 1 Ozkan Sezer 2016-11-01 05:24:50 UTC
Duplicate of https://bugzilla.libsdl.org/show_bug.cgi?id=3472 ?
Comment 2 Marisa 2016-11-01 11:53:41 UTC
I have investigated that bug and it's unrelated to my case.

I do not use ibus, but rather uim, which seems to be responsible for this happening.

Instead of one keydown and one keyup event being sent at the same time like in that bug, I get two keydowns, one of them with the repeat flag.

I wrote a program to show this:

#include <SDL.h>

int main( void )
{
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window *w = SDL_CreateWindow("keydown",SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED,256,256,SDL_WINDOW_SHOWN);
	SDL_Event e;
	int quit = 0;
	while ( !quit )
	{
		while ( SDL_PollEvent(&e) )
		{
			if ( e.type == SDL_QUIT ) quit = 1;
			else if ( e.type == SDL_KEYDOWN )
			{
				printf("keydown:\n scancode %u\n repeat %u\n",
					e.key.keysym.scancode,e.key.repeat);
				if ( e.key.keysym.scancode == 41 ) quit = 1;
			}
			else if ( e.type == SDL_KEYUP )
			{
				printf("keyup:\n scancode %u\n repeat %u\n",
					e.key.keysym.scancode,e.key.repeat);
			}
		}
	}
	SDL_DestroyWindow(w);
	SDL_Quit();
}

The output when I do a single press of enter is:

keydown:
 scancode 40
 repeat 0
keydown:
 scancode 40
 repeat 1
keyup:
 scancode 40
 repeat 0

If I unset XMODIFIERS (which is set to @im=uim), the repeated keydown does not happen.
Comment 3 Sam Lantinga 2016-11-01 17:15:39 UTC
Alex, can you look into this?

Thanks!
Comment 4 Alex Baines 2016-11-01 17:41:16 UTC
Created attachment 2597 [details]
skip resent filtered keys

I believe this fixes it.
Comment 5 Sam Lantinga 2016-11-01 17:51:25 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/251691cfeaa0
Comment 6 Alex Baines 2016-11-02 04:23:57 UTC
Created attachment 2598 [details]
don't skip sending text for resent events

I realized overnight that my patch probably broke text input events with UIM, and I confirmed that it does. Can't believe I overlooked that... I've been making stupid mistakes in these patches recently, sorry.

Anyway, *this* one seems to fix it properly. Knowing my luck it probably breaks something else.
Comment 7 Sam Lantinga 2016-11-02 17:52:46 UTC
Got it, thanks!
https://hg.libsdl.org/SDL/rev/8b8a45c000f9