GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw) { int keyDown=0; char vk; GHOST_SystemWin32 * system = (GHOST_SystemWin32 *)getSystem(); GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk); GHOST_EventKey* event; if (key != GHOST_kKeyUnknown) { char utf8_char[6] = {0} ; wchar_t utf16[2]={0}; BYTE state[256]; GetKeyboardState((PBYTE)state); if(ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout)) WideCharToMultiByte(CP_UTF8, 0, (wchar_t*)utf16, 1, (LPSTR) utf8_char, 5, NULL,NULL); else *utf8_char = 0; if(!keyDown) utf8_char[0] = '\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; #endif } else { event = 0; } return event; }
GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw) { int keyDown=0; char vk; 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'; unsigned short utf16[2]={0}; BYTE state[256]; GetKeyboardState((PBYTE)state); if(ToAsciiEx(vk, 0, state, utf16, 0, system->m_keylayout)) WideCharToMultiByte(CP_ACP, 0x00000400, (wchar_t*)utf16, 1, (LPSTR) &ascii, 1, NULL,NULL); event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown: GHOST_kEventKeyUp, window, key, ascii); #ifdef GHOST_DEBUG std::cout << ascii << std::endl; #endif } else { event = 0; } return event; }
GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw) { int keyDown = 0; char vk; GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem(); GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk); GHOST_EventKey *event; if (key != GHOST_kKeyUnknown) { char utf8_char[6] = {0}; char ascii = 0; wchar_t utf16[3] = {0}; BYTE state[256] = {0}; int r; GetKeyboardState((PBYTE)state); // don't call ToUnicodeEx on dead keys as it clears the buffer and so won't allow diacritical composition. if (MapVirtualKeyW(vk,2) != 0) { // todo: ToUnicodeEx can respond with up to 4 utf16 chars (only 2 here). Could be up to 24 utf8 bytes. if ((r = ToUnicodeEx(vk, raw.data.keyboard.MakeCode, state, utf16, 2, 0, system->m_keylayout))) { if ((r > 0 && r < 3)) { utf16[r] = 0; conv_utf_16_to_8(utf16, utf8_char, 6); } else if (r == -1) { utf8_char[0] = '\0'; } } } if (!keyDown) { utf8_char[0] = '\0'; ascii = '\0'; } else { ascii = utf8_char[0] & 0x80 ? '?' : utf8_char[0]; } event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, key, ascii, utf8_char); #ifdef GHOST_DEBUG std::cout << ascii << std::endl; #endif } else { event = 0; } return event; }