Fixed bug #618 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 13 Apr 2009 08:42:09 +0000
branchSDL-1.2
changeset 4170092c0bc69155
parent 4169 27c0db0fbfad
child 4171 3012f1c37361
Fixed bug #618

Description From Tim Angus 2008-08-30 12:23:56 (-) [reply]

As we all know SDL 1.2 doesn't handle dead keys well since one key press
potentially equals two (or more) characters. For example, on many layouts,
keying <backquote>,<space> results in <no character>,<backquote><space>. Since
the unicode member of the SDL_keysym struct only has room for one character,
only one can be returned.

On Linux, the first character is returned. On Windows however, unless the exact
number of characters generated by the keypress is 1, nothing is returned. The
following patch addresses this inconsistency.

Updated patch which includes a further fix to the handling of the numpad when
numlock is on. This further fix is courtesy Amanieu d'Antras.
src/video/windib/SDL_dibevents.c
src/video/windx5/SDL_dx5events.c
     1.1 --- a/src/video/windib/SDL_dibevents.c	Mon Apr 13 08:38:04 2009 +0000
     1.2 +++ b/src/video/windib/SDL_dibevents.c	Mon Apr 13 08:42:09 2009 +0000
     1.3 @@ -552,7 +552,13 @@
     1.4  		Uint16	wchars[2];
     1.5  
     1.6  		GetKeyboardState(keystate);
     1.7 -		if (SDL_ToUnicode((UINT)vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) == 1)
     1.8 +		/* Numlock isn't taken into account in ToUnicode,
     1.9 +		 * so we handle it as a special case here */
    1.10 +		if ((keystate[VK_NUMLOCK] & 1) && vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9)
    1.11 +		{
    1.12 +			keysym->unicode = vkey - VK_NUMPAD0 + '0';
    1.13 +		}
    1.14 +		else if (SDL_ToUnicode((UINT)vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) > 0)
    1.15  		{
    1.16  			keysym->unicode = wchars[0];
    1.17  		}
     2.1 --- a/src/video/windx5/SDL_dx5events.c	Mon Apr 13 08:38:04 2009 +0000
     2.2 +++ b/src/video/windx5/SDL_dx5events.c	Mon Apr 13 08:42:09 2009 +0000
     2.3 @@ -912,7 +912,13 @@
     2.4  		keysym->unicode = vkey;
     2.5  #else
     2.6  		GetKeyboardState(keystate);
     2.7 -		if (SDL_ToUnicode(vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) == 1)
     2.8 +		/* Numlock isn't taken into account in ToUnicode,
     2.9 +		 * so we handle it as a special case here */
    2.10 +		if ((keystate[VK_NUMLOCK] & 1) && vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9)
    2.11 +		{
    2.12 +			keysym->unicode = vkey - VK_NUMPAD0 + '0';
    2.13 +		}
    2.14 +		else if (SDL_ToUnicode(vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) > 0)
    2.15  		{
    2.16  			keysym->unicode = wchars[0];
    2.17  		}