Skip to content

Commit

Permalink
backport bug #3332 (win32 deadkeys) patch:
Browse files Browse the repository at this point in the history
https://bugzilla.libsdl.org/show_bug.cgi?id=3332
Eric Wasylishen <ewasylishen@gmail.com>
  • Loading branch information
sezero committed Mar 24, 2018
1 parent 2743d4e commit d70a3a6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/events/SDL_keyboard.c
Expand Up @@ -334,8 +334,16 @@ int SDL_KeyboardInit(void)
/* Done. Whew. */
return(0);
}

#ifdef _WIN32
extern void WIN_ResetDeadKeys(void);
#endif

void SDL_KeyboardQuit(void)
{
#ifdef _WIN32
WIN_ResetDeadKeys();
#endif
}

/* We lost the keyboard, so post key up messages for all pressed keys */
Expand All @@ -362,6 +370,11 @@ int SDL_EnableUNICODE(int enable)
if ( enable >= 0 ) {
SDL_TranslateUNICODE = enable;
}
#ifdef _WIN32
if (enable != old_mode) {
WIN_ResetDeadKeys();
}
#endif
return(old_mode);
}

Expand Down
31 changes: 31 additions & 0 deletions src/video/windib/SDL_dibevents.c
Expand Up @@ -583,6 +583,37 @@ static int SDL_MapVirtualKey(int scancode, int vkey)
return mvke?mvke:vkey;
}

#ifndef MAPVK_VK_TO_VSC
#define MAPVK_VK_TO_VSC 0
#endif
void
WIN_ResetDeadKeys(void)
{
/*
if a deadkey has been typed, but not the next character (which the deadkey might modify),
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];
UINT keycode, scancode, i;
int result;

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

for (i = 0; i < 5; i++) {
result = SDL_ToUnicode(keycode, scancode, keyboardState, (LPWSTR)buffer, 16, 0);
if (result > 0) {
return; /* success */
}
}
}

static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed)
{
/* Set the keysym information */
Expand Down

0 comments on commit d70a3a6

Please sign in to comment.