Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Reset the keyboard when we lose input focus
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 7, 2012
1 parent ced78c6 commit 386b48e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/events/SDL_keyboard.c
Expand Up @@ -28,6 +28,8 @@
#include "../video/SDL_sysvideo.h"


/*#define DEBUG_KEYBOARD*/

/* Global keyboard information */

typedef struct SDL_Keyboard SDL_Keyboard;
Expand Down Expand Up @@ -563,6 +565,9 @@ SDL_ResetKeyboard(void)
SDL_Keyboard *keyboard = &SDL_keyboard;
SDL_Scancode scancode;

#ifdef DEBUG_KEYBOARD
printf("Resetting keyboard\n");
#endif
for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keystate[scancode] == SDL_PRESSED) {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
Expand Down Expand Up @@ -633,6 +638,9 @@ SDL_SetKeyboardFocus(SDL_Window * window)
video->StartTextInput(video);
}
}
} else {
/* We won't get anymore keyboard messages, so reset keyboard state */
SDL_ResetKeyboard();
}
}

Expand All @@ -648,7 +656,7 @@ SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
if (!scancode) {
return 0;
}
#if 0
#ifdef DEBUG_KEYBOARD
printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
state == SDL_PRESSED ? "pressed" : "released");
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -258,6 +258,13 @@ X11_DispatchEvent(_THIS)
#ifdef DEBUG_XEVENTS
printf("window %p: FocusIn!\n", data);
#endif
if (data->pending_focus == PENDING_FOCUS_OUT &&
data->window == SDL_GetKeyboardFocus()) {
/* We want to reset the keyboard here, because we may have
missed keyboard messages after our previous FocusOut.
*/
SDL_ResetKeyboard();
}
data->pending_focus = PENDING_FOCUS_IN;
data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_IN_TIME;
}
Expand Down

0 comments on commit 386b48e

Please sign in to comment.