Skip to content

Commit

Permalink
Reset dead keys when the SDL window loses focus, so dead keys pressed…
Browse files Browse the repository at this point in the history
… in SDL applications don't affect text input into other applications.
  • Loading branch information
slouken committed Oct 1, 2016
1 parent 1e6e595 commit 0b57696
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -451,6 +451,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

if (SDL_GetKeyboardFocus() == data->window) {
SDL_SetKeyboardFocus(NULL);
WIN_ResetDeadKeys();
}

ClipCursor(NULL);
Expand Down
10 changes: 3 additions & 7 deletions src/video/windows/SDL_windowskeyboard.c
Expand Up @@ -165,7 +165,6 @@ WIN_ResetDeadKeys()
this tries to undo the effect pressing the deadkey.
see: http://archives.miloush.net/michkap/archive/2006/09/10/748775.html
*/

BYTE keyboardState[256];
WCHAR buffer[16];
int keycode, scancode, result, i;
Expand All @@ -174,17 +173,14 @@ WIN_ResetDeadKeys()

keycode = VK_SPACE;
scancode = MapVirtualKey(keycode, MAPVK_VK_TO_VSC);
if (scancode == 0)
{
if (scancode == 0) {
/* the keyboard doesn't have this key */
return;
}

for (i = 0; i < 5; i++)
{
for (i = 0; i < 5; i++) {
result = ToUnicode(keycode, scancode, keyboardState, (LPWSTR)buffer, 16, 0);
if (result > 0)
{
if (result > 0) {
/* success */
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/video/windows/SDL_windowskeyboard.h
Expand Up @@ -27,6 +27,8 @@ extern void WIN_InitKeyboard(_THIS);
extern void WIN_UpdateKeymap(void);
extern void WIN_QuitKeyboard(_THIS);

extern void WIN_ResetDeadKeys(void);

extern void WIN_StartTextInput(_THIS);
extern void WIN_StopTextInput(_THIS);
extern void WIN_SetTextInputRect(_THIS, SDL_Rect *rect);
Expand Down

0 comments on commit 0b57696

Please sign in to comment.