src/video/win32/SDL_win32keyboard.c
changeset 2311 54e21acfec5a
parent 2308 514f7c1651fc
child 2317 f537a293b3da
     1.1 --- a/src/video/win32/SDL_win32keyboard.c	Sat Feb 09 07:18:38 2008 +0000
     1.2 +++ b/src/video/win32/SDL_win32keyboard.c	Sat Feb 09 22:28:27 2008 +0000
     1.3 @@ -26,17 +26,43 @@
     1.4  #include "../../events/SDL_keyboard_c.h"
     1.5  #include "../../events/scancodes_win32.h"
     1.6  
     1.7 +#ifndef MAPVK_VK_TO_VSC
     1.8 +#define MAPVK_VK_TO_VSC     0
     1.9 +#endif
    1.10 +#ifndef MAPVK_VSC_TO_VK
    1.11 +#define MAPVK_VSC_TO_VK     1
    1.12 +#endif
    1.13 +#ifndef MAPVK_VK_TO_CHAR
    1.14 +#define MAPVK_VK_TO_CHAR    2
    1.15 +#endif
    1.16 +
    1.17 +/* Alphabetic scancodes for PC keyboards */
    1.18 +BYTE alpha_scancodes[26] = {
    1.19 +    30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
    1.20 +    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
    1.21 +};
    1.22 +
    1.23  void
    1.24  WIN_InitKeyboard(_THIS)
    1.25  {
    1.26      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    1.27      SDL_Keyboard keyboard;
    1.28 +    int i;
    1.29 +
    1.30 +    /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
    1.31 +    if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T'-'A']) {
    1.32 +printf("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    1.33 +        for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    1.34 +            alpha_scancodes[i] = MapVirtualKey('A'+i, MAPVK_VK_TO_VSC);
    1.35 +printf("%d = %d\n", i, alpha_scancodes[i]);
    1.36 +        }
    1.37 +    }
    1.38  
    1.39      data->key_layout = win32_scancode_table;
    1.40  
    1.41      SDL_zero(keyboard);
    1.42      data->keyboard = SDL_AddKeyboard(&keyboard, -1);
    1.43 -    WIN_UpdateKeymap(_this);
    1.44 +    WIN_UpdateKeymap(data->keyboard);
    1.45  
    1.46      SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
    1.47      SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
    1.48 @@ -44,9 +70,8 @@
    1.49  }
    1.50  
    1.51  void
    1.52 -WIN_UpdateKeymap(_THIS)
    1.53 +WIN_UpdateKeymap(int keyboard)
    1.54  {
    1.55 -    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    1.56      int i;
    1.57      SDL_scancode scancode;
    1.58      SDLKey keymap[SDL_NUM_SCANCODES];
    1.59 @@ -61,12 +86,16 @@
    1.60              (keymap[scancode] & SDLK_SCANCODE_MASK)) {
    1.61              continue;
    1.62          }
    1.63 -#ifndef MAPVK_VK_TO_CHAR
    1.64 -#define MAPVK_VK_TO_CHAR    2
    1.65 -#endif
    1.66 -        keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
    1.67 +
    1.68 +        /* Alphabetic keys are handled specially, since Windows remaps them */
    1.69 +        if (i >= 'A' && i <= 'Z') {
    1.70 +            BYTE vsc = alpha_scancodes[i-'A'];
    1.71 +            keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20;
    1.72 +        } else {
    1.73 +            keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
    1.74 +        }
    1.75      }
    1.76 -    SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
    1.77 +    SDL_SetKeymap(keyboard, 0, keymap, SDL_NUM_SCANCODES);
    1.78  }
    1.79  
    1.80  void