backport bug #3332 (win32 deadkeys) patch: SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Sat, 24 Mar 2018 23:38:50 +0300
branchSDL-1.2
changeset 119776cf3a08b42dc
parent 11976 42535a774733
child 11978 2dfa07d52047
backport bug #3332 (win32 deadkeys) patch:

https://bugzilla.libsdl.org/show_bug.cgi?id=3332
Eric Wasylishen <ewasylishen@gmail.com>
src/events/SDL_keyboard.c
src/video/windib/SDL_dibevents.c
     1.1 --- a/src/events/SDL_keyboard.c	Sat Mar 24 23:10:59 2018 +0300
     1.2 +++ b/src/events/SDL_keyboard.c	Sat Mar 24 23:38:50 2018 +0300
     1.3 @@ -334,8 +334,16 @@
     1.4  	/* Done.  Whew. */
     1.5  	return(0);
     1.6  }
     1.7 +
     1.8 +#ifdef _WIN32
     1.9 +extern void WIN_ResetDeadKeys(void);
    1.10 +#endif
    1.11 +
    1.12  void SDL_KeyboardQuit(void)
    1.13  {
    1.14 +#ifdef _WIN32
    1.15 +	WIN_ResetDeadKeys();
    1.16 +#endif
    1.17  }
    1.18  
    1.19  /* We lost the keyboard, so post key up messages for all pressed keys */
    1.20 @@ -362,6 +370,11 @@
    1.21  	if ( enable >= 0 ) {
    1.22  		SDL_TranslateUNICODE = enable;
    1.23  	}
    1.24 +#ifdef _WIN32
    1.25 +	if (enable != old_mode) {
    1.26 +		WIN_ResetDeadKeys();
    1.27 +	}
    1.28 +#endif
    1.29  	return(old_mode);
    1.30  }
    1.31  
     2.1 --- a/src/video/windib/SDL_dibevents.c	Sat Mar 24 23:10:59 2018 +0300
     2.2 +++ b/src/video/windib/SDL_dibevents.c	Sat Mar 24 23:38:50 2018 +0300
     2.3 @@ -583,6 +583,37 @@
     2.4  	return mvke?mvke:vkey;
     2.5  }
     2.6  
     2.7 +#ifndef MAPVK_VK_TO_VSC
     2.8 +#define MAPVK_VK_TO_VSC 0
     2.9 +#endif
    2.10 +void
    2.11 +WIN_ResetDeadKeys(void)
    2.12 +{
    2.13 +    /*
    2.14 +    if a deadkey has been typed, but not the next character (which the deadkey might modify),
    2.15 +    this tries to undo the effect pressing the deadkey.
    2.16 +    see: http://archives.miloush.net/michkap/archive/2006/09/10/748775.html
    2.17 +    */
    2.18 +    BYTE keyboardState[256];
    2.19 +    WCHAR buffer[16];
    2.20 +    UINT keycode, scancode, i;
    2.21 +    int result;
    2.22 +
    2.23 +    GetKeyboardState(keyboardState);
    2.24 +    keycode = VK_SPACE;
    2.25 +    scancode = MapVirtualKey(keycode, MAPVK_VK_TO_VSC);
    2.26 +    if (scancode == 0) {
    2.27 +        return; /* the keyboard doesn't have this key */
    2.28 +    }
    2.29 +
    2.30 +    for (i = 0; i < 5; i++) {
    2.31 +        result = SDL_ToUnicode(keycode, scancode, keyboardState, (LPWSTR)buffer, 16, 0);
    2.32 +        if (result > 0) {
    2.33 +            return; /* success */
    2.34 +        }
    2.35 +    }
    2.36 +}
    2.37 +
    2.38  static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed)
    2.39  {
    2.40  	/* Set the keysym information */