Index: windib/SDL_dibevents.c =================================================================== RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/windib/SDL_dibevents.c,v retrieving revision 1.25 diff -u -r1.25 SDL_dibevents.c --- windib/SDL_dibevents.c 29 Sep 2005 09:43:00 -0000 1.25 +++ windib/SDL_dibevents.c 12 Jan 2006 03:09:48 -0000 @@ -59,6 +59,9 @@ and give him a chance to handle some messages. */ static WNDPROC userWindowProc = NULL; +/* flag to disjoint ToUnicode() on WinNT and ToAscii() for Win95 compat */ +static int HaveToUnicode; + /* The main Win32 event handler */ LONG DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -341,17 +344,34 @@ keysym->sym = VK_keymap[vkey]; keysym->mod = KMOD_NONE; keysym->unicode = 0; - if ( pressed && SDL_TranslateUNICODE ) { /* Someday use ToUnicode() */ + if ( pressed && SDL_TranslateUNICODE ) { #ifdef NO_GETKEYBOARDSTATE /* Uh oh, better hope the vkey is close enough.. */ keysym->unicode = vkey; #else BYTE keystate[256]; - BYTE chars[2]; GetKeyboardState(keystate); - if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) { - keysym->unicode = chars[0]; + + if ( HaveToUnicode ) { + /* can do Unicode input - yay! */ + WCHAR chars[4]; /* 4 is chosen arbitrarily */ + + /* FIXME: ToUnicode() may yield more than one + * character, so we need a mechanism to allow for + * this (perhaps generate null keypress events with + * a unicode value) + */ + if ( ToUnicode(vkey,scancode,keystate,chars,4,0) > 0 ) { + keysym->unicode = chars[0]; + } + } else { + /* probably Win95 - no Unicode */ + BYTE chars[2]; + + if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) { + keysym->unicode = chars[0]; + } } #endif /* NO_GETKEYBOARDSTATE */ } @@ -363,6 +383,12 @@ #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) wchar_t *SDL_windowid_t; #endif + OSVERSIONINFO ver; + + /* we can only use ToUnicode() on NT */ + ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + GetVersionEx(&ver); + HaveToUnicode = (ver.dwPlatformId == VER_PLATFORM_WIN32_NT); #ifndef CS_BYTEALIGNCLIENT #define CS_BYTEALIGNCLIENT 0 Index: windx5/SDL_dx5events.c =================================================================== RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/windx5/SDL_dx5events.c,v retrieving revision 1.25 diff -u -r1.25 SDL_dx5events.c --- windx5/SDL_dx5events.c 11 Aug 2005 05:08:28 -0000 1.25 +++ windx5/SDL_dx5events.c 12 Jan 2006 03:09:49 -0000 @@ -68,6 +68,9 @@ and give him a chance to handle some messages. */ static WNDPROC userWindowProc = NULL; +/* flag to disjoint ToUnicode() on WinNT and ToAscii() for Win95 compat */ +static int HaveToUnicode; + static HWND GetTopLevelParent(HWND hWnd) { HWND hParentWnd; @@ -824,11 +827,10 @@ keysym->sym = DIK_keymap[scancode]; keysym->mod = KMOD_NONE; keysym->unicode = 0; - if ( pressed && SDL_TranslateUNICODE ) { /* Someday use ToUnicode() */ + if ( pressed && SDL_TranslateUNICODE ) { UINT vkey; #ifndef NO_GETKEYBOARDSTATE BYTE keystate[256]; - BYTE chars[2]; #endif vkey = MapVirtualKey(scancode, 1); @@ -837,8 +839,26 @@ keysym->unicode = vkey; #else GetKeyboardState(keystate); - if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) { - keysym->unicode = chars[0]; + + if ( HaveToUnicode ) { + /* can do Unicode input - yay! */ + WCHAR chars[4]; /* 4 is chosen arbitrarily */ + + /* FIXME: ToUnicode() may yield more than one + * character, so we need a mechanism to allow for + * this (perhaps generate null keypress events with + * a unicode value) + */ + if ( ToUnicode(vkey,scancode,keystate,chars,4,0) > 0 ) { + keysym->unicode = chars[0]; + } + } else { + /* probably Win95 - no Unicode */ + BYTE chars[2]; + + if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) { + keysym->unicode = chars[0]; + } } #endif } @@ -848,6 +868,12 @@ int DX5_CreateWindow(_THIS) { int i; + OSVERSIONINFO ver; + + /* we can only use ToUnicode() on NT */ + ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + GetVersionEx(&ver); + HaveToUnicode = (ver.dwPlatformId == VER_PLATFORM_WIN32_NT); /* Clear out DirectInput variables in case we fail */ for ( i=0; i