UTF8 input support for Windows.
authorAlexander Kuznetsov <kuzsasha@gmail.com>
Fri, 21 Oct 2011 17:40:35 +0000 (17:40 +0000)
committerAlexander Kuznetsov <kuzsasha@gmail.com>
Fri, 21 Oct 2011 17:40:35 +0000 (17:40 +0000)
ToDo:
* add support for dead keys
* other input methods (for hieroglyphs)

intern/ghost/intern/GHOST_SystemWin32.cpp

index 24b6474732e64b488f8efe7318b3aae65178a53a..99ce81165adf175858ca6618f93aff11efd375fa 100644 (file)
@@ -712,21 +712,21 @@ GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINP
        GHOST_SystemWin32 * system = (GHOST_SystemWin32 *)getSystem();
        GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk);
        GHOST_EventKey* event;
+
        if (key != GHOST_kKeyUnknown) {
-               char ascii = '\0';
+               char utf8_char[6] = {0} ;
 
-               unsigned short utf16[2]={0};
+               wchar_t utf16[2]={0};
                BYTE state[256];
-               GetKeyboardState((PBYTE)state);
+               GetKeyboardState((PBYTE)state);  
 
-               if(ToAsciiEx(vk, 0, state, utf16, 0, system->m_keylayout))
-                               WideCharToMultiByte(CP_ACP, 0x00000400, 
+               if(ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout))
+                       WideCharToMultiByte(CP_UTF8, 0, 
                                                                        (wchar_t*)utf16, 1,
-                                                                       (LPSTR) &ascii, 1,
-                                                                       NULL,NULL);
-
-               /* TODO, last arg is utf8, need to pass utf8 arg */
-               event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown: GHOST_kEventKeyUp, window, key, ascii, NULL);
+                                                                       (LPSTR) utf8_char, 5,
+                                                                       NULL,NULL); else *utf8_char = 0;
+               
+               event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown: GHOST_kEventKeyUp, window, key, (*utf8_char & 0x80)?'?':*utf8_char, utf8_char);
                
 #ifdef GHOST_DEBUG
                std::cout << ascii << std::endl;