[SDL] SDL_GetKeyboardState bug ? Key stuck after window moved

sgrsgsrg thephanoo at gmail.com
Wed Sep 14 13:53:19 PDT 2016

Some news.

The only way i found to reset a stuck key is to make the window lose then gain its focus.

This code will force focus change if a key was pressed while the window was moved, thus correcting the stucked key glitch


while (SDL_PollEvent(&e)) {
	switch (e.type){
		if (e.window.event == SDL_WINDOWEVENT_MOVED) {
			// check if a key was already pressed
			int sdl_bug = 0;
			for (int i = 0; i < 7; i++){ // the 7 keyboard keys i use in my game
				if (keys[i]){
					sdl_bug = 1;
			if (sdl_bug){ // hack

Hacks are ugly, it'd be nice if some investigation could be done

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20160914/2be9fd08/attachment.htm>

More information about the SDL mailing list