src/video/win32/SDL_win32keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 09 May 2010 20:47:22 -0700
changeset 4465 3e69e077cb95
parent 3697 f7b03b6838cb
child 4561 e4b2b7207f79
child 4747 5284a3b3217a
permissions -rw-r--r--
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.

Plus, this lets me start implementing cursor support.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #include "SDL_win32video.h"
    25 
    26 #include "../../events/SDL_keyboard_c.h"
    27 #include "../../events/scancodes_win32.h"
    28 
    29 #ifndef MAPVK_VK_TO_VSC
    30 #define MAPVK_VK_TO_VSC     0
    31 #endif
    32 #ifndef MAPVK_VSC_TO_VK
    33 #define MAPVK_VSC_TO_VK     1
    34 #endif
    35 #ifndef MAPVK_VK_TO_CHAR
    36 #define MAPVK_VK_TO_CHAR    2
    37 #endif
    38 
    39 /* Alphabetic scancodes for PC keyboards */
    40 BYTE alpha_scancodes[26] = {
    41     30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
    42     25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
    43 };
    44 
    45 BYTE keypad_scancodes[10] = {
    46     82, 79, 80, 81, 75, 76, 77, 71, 72, 73
    47 };
    48 
    49 void
    50 WIN_InitKeyboard(_THIS)
    51 {
    52     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    53     int i;
    54 
    55     /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
    56     if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
    57 #if 0
    58         printf
    59             ("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");
    60 #endif
    61         for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    62             alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
    63 #if 0
    64             printf("%d = %d\n", i, alpha_scancodes[i]);
    65 #endif
    66         }
    67     }
    68     if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
    69 #if 0
    70         printf
    71             ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    72 #endif
    73         for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    74             keypad_scancodes[i] =
    75                 MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
    76 #if 0
    77             printf("%d = %d\n", i, keypad_scancodes[i]);
    78 #endif
    79         }
    80     }
    81 
    82     data->key_layout = win32_scancode_table;
    83 
    84     WIN_UpdateKeymap();
    85 
    86     SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
    87     SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
    88     SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
    89 }
    90 
    91 void
    92 WIN_UpdateKeymap()
    93 {
    94     int i;
    95     SDL_scancode scancode;
    96     SDLKey keymap[SDL_NUM_SCANCODES];
    97 
    98     SDL_GetDefaultKeymap(keymap);
    99 
   100     for (i = 0; i < SDL_arraysize(win32_scancode_table); i++) {
   101 
   102         /* Make sure this scancode is a valid character scancode */
   103         scancode = win32_scancode_table[i];
   104         if (scancode == SDL_SCANCODE_UNKNOWN ||
   105             (keymap[scancode] & SDLK_SCANCODE_MASK)) {
   106             continue;
   107         }
   108 
   109         /* Alphabetic keys are handled specially, since Windows remaps them */
   110         if (i >= 'A' && i <= 'Z') {
   111             BYTE vsc = alpha_scancodes[i - 'A'];
   112             keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20;
   113         } else {
   114             keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
   115         }
   116     }
   117     SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
   118 }
   119 
   120 void
   121 WIN_QuitKeyboard(_THIS)
   122 {
   123 }
   124 
   125 /* vi: set ts=4 sw=4 expandtab: */