src/video/win32/SDL_win32keyboard.c
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 17:06:37 +0000
branchgsoc2008_force_feedback
changeset 2498 ab567bd667bf
parent 2324 3202e4826c57
child 2698 e1da92da346c
child 2724 0e2b65f32298
child 3767 abc8acb8e3d7
permissions -rw-r--r--
Fixed various mistakes in the doxygen.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 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 BYTE keypad_scancodes[10] = {
    45     82, 79, 80, 81, 75, 76, 77, 71, 72, 73
    46 };
    47 
    48 void
    49 WIN_InitKeyboard(_THIS)
    50 {
    51     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    52     SDL_Keyboard keyboard;
    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         printf
    58             ("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");
    59         for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    60             alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
    61             printf("%d = %d\n", i, alpha_scancodes[i]);
    62         }
    63     }
    64     if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
    65         printf
    66             ("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");
    67         for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    68             keypad_scancodes[i] =
    69                 MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
    70             printf("%d = %d\n", i, keypad_scancodes[i]);
    71         }
    72     }
    73 
    74     data->key_layout = win32_scancode_table;
    75 
    76     SDL_zero(keyboard);
    77     data->keyboard = SDL_AddKeyboard(&keyboard, -1);
    78     WIN_UpdateKeymap(data->keyboard);
    79 
    80     SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
    81     SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
    82     SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
    83 }
    84 
    85 void
    86 WIN_UpdateKeymap(int keyboard)
    87 {
    88     int i;
    89     SDL_scancode scancode;
    90     SDLKey keymap[SDL_NUM_SCANCODES];
    91 
    92     SDL_GetDefaultKeymap(keymap);
    93 
    94     for (i = 0; i < SDL_arraysize(win32_scancode_table); i++) {
    95 
    96         /* Make sure this scancode is a valid character scancode */
    97         scancode = win32_scancode_table[i];
    98         if (scancode == SDL_SCANCODE_UNKNOWN ||
    99             (keymap[scancode] & SDLK_SCANCODE_MASK)) {
   100             continue;
   101         }
   102 
   103         /* Alphabetic keys are handled specially, since Windows remaps them */
   104         if (i >= 'A' && i <= 'Z') {
   105             BYTE vsc = alpha_scancodes[i - 'A'];
   106             keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20;
   107         } else {
   108             keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
   109         }
   110     }
   111     SDL_SetKeymap(keyboard, 0, keymap, SDL_NUM_SCANCODES);
   112 }
   113 
   114 void
   115 WIN_QuitKeyboard(_THIS)
   116 {
   117     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   118 
   119     SDL_DelKeyboard(data->keyboard);
   120 }
   121 
   122 /* vi: set ts=4 sw=4 expandtab: */