src/video/win32/SDL_win32keyboard.c
changeset 2308 514f7c1651fc
parent 1895 c121d94672cb
child 2311 54e21acfec5a
     1.1 --- a/src/video/win32/SDL_win32keyboard.c	Thu Feb 07 16:14:43 2008 +0000
     1.2 +++ b/src/video/win32/SDL_win32keyboard.c	Fri Feb 08 08:35:49 2008 +0000
     1.3 @@ -24,6 +24,7 @@
     1.4  #include "SDL_win32video.h"
     1.5  
     1.6  #include "../../events/SDL_keyboard_c.h"
     1.7 +#include "../../events/scancodes_win32.h"
     1.8  
     1.9  void
    1.10  WIN_InitKeyboard(_THIS)
    1.11 @@ -31,8 +32,41 @@
    1.12      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    1.13      SDL_Keyboard keyboard;
    1.14  
    1.15 +    data->key_layout = win32_scancode_table;
    1.16 +
    1.17      SDL_zero(keyboard);
    1.18      data->keyboard = SDL_AddKeyboard(&keyboard, -1);
    1.19 +    WIN_UpdateKeymap(_this);
    1.20 +
    1.21 +    SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
    1.22 +    SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
    1.23 +    SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
    1.24 +}
    1.25 +
    1.26 +void
    1.27 +WIN_UpdateKeymap(_THIS)
    1.28 +{
    1.29 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    1.30 +    int i;
    1.31 +    SDL_scancode scancode;
    1.32 +    SDLKey keymap[SDL_NUM_SCANCODES];
    1.33 +
    1.34 +    SDL_GetDefaultKeymap(keymap);
    1.35 +
    1.36 +    for (i = 0; i < SDL_arraysize(win32_scancode_table); i++) {
    1.37 +
    1.38 +        /* Make sure this scancode is a valid character scancode */
    1.39 +        scancode = win32_scancode_table[i];
    1.40 +        if (scancode == SDL_SCANCODE_UNKNOWN ||
    1.41 +            (keymap[scancode] & SDLK_SCANCODE_MASK)) {
    1.42 +            continue;
    1.43 +        }
    1.44 +#ifndef MAPVK_VK_TO_CHAR
    1.45 +#define MAPVK_VK_TO_CHAR    2
    1.46 +#endif
    1.47 +        keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
    1.48 +    }
    1.49 +    SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
    1.50  }
    1.51  
    1.52  void