Skip to content
Permalink
Browse files

backport bug #3332 (win32 deadkeys) patch:

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 d70a3a66bdd03e5934c6e5bd271cb830b05e3c6c
Showing with 44 additions and 0 deletions.
  1. +13 −0 src/events/SDL_keyboard.c
  2. +31 −0 src/video/windib/SDL_dibevents.c
@@ -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 */
@@ -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);
}

@@ -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 */

0 comments on commit d70a3a6

Please sign in to comment.