static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed) { /* Set the keysym information */ keysym->scancode = (unsigned char) scancode; keysym->mod = KMOD_NONE; keysym->unicode = 0; if ((vkey == VK_RETURN) && (scancode & 0x100)) { /* No VK_ code for the keypad enter key */ keysym->sym = SDLK_KP_ENTER; } else { keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)]; } if ( pressed && SDL_TranslateUNICODE ) { #ifdef NO_GETKEYBOARDSTATE /* Uh oh, better hope the vkey is close enough.. */ if((keysym->sym == vkey) || (vkey > 0x7f)) keysym->unicode = vkey; #else BYTE keystate[256]; Uint16 wchars[2]; GetKeyboardState(keystate); /* Numlock isn't taken into account in ToUnicode, * so we handle it as a special case here */ if ((keystate[VK_NUMLOCK] & 1) && vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9) { keysym->unicode = vkey - VK_NUMPAD0 + '0'; } else if (SDL_ToUnicode((UINT)vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) > 0) { keysym->unicode = wchars[0]; } #endif /* NO_GETKEYBOARDSTATE */ } #if 0 { HKL hLayoutCurrent = GetKeyboardLayout(0); int sc = scancode & 0xFF; printf("SYM:%d, VK:0x%02X, SC:0x%04X, US:(1:0x%02X, 3:0x%02X), " "Current:(1:0x%02X, 3:0x%02X)\n", keysym->sym, vkey, scancode, MapVirtualKeyEx(sc, 1, hLayoutUS), MapVirtualKeyEx(sc, 3, hLayoutUS), MapVirtualKeyEx(sc, 1, hLayoutCurrent), MapVirtualKeyEx(sc, 3, hLayoutCurrent) ); } #endif return(keysym); }
static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed) { keysym->scancode = (unsigned char) scancode; keysym->mod = KMOD_NONE; keysym->unicode = 0; if ((vkey == VK_RETURN) && (scancode & 0x100)) { keysym->sym = SDLK_KP_ENTER; } else { keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)]; } if ( pressed && SDL_TranslateUNICODE ) { #ifdef NO_GETKEYBOARDSTATE if((keysym->sym == vkey) || (vkey > 0x7f)) keysym->unicode = vkey; #else BYTE keystate[256]; Uint16 wchars[2]; GetKeyboardState(keystate); if ((keystate[VK_NUMLOCK] & 1) && vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9) { keysym->unicode = vkey - VK_NUMPAD0 + '0'; } else if (SDL_ToUnicode((UINT)vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) > 0) { keysym->unicode = wchars[0]; } #endif } #if 0 { HKL hLayoutCurrent = GetKeyboardLayout(0); int sc = scancode & 0xFF; printf("SYM:%d, VK:0x%02X, SC:0x%04X, US:(1:0x%02X, 3:0x%02X), " "Current:(1:0x%02X, 3:0x%02X)\n", keysym->sym, vkey, scancode, MapVirtualKeyEx(sc, 1, hLayoutUS), MapVirtualKeyEx(sc, 3, hLayoutUS), MapVirtualKeyEx(sc, 1, hLayoutCurrent), MapVirtualKeyEx(sc, 3, hLayoutCurrent) ); } #endif return(keysym); }