src/video/win32/SDL_win32keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Feb 2008 08:35:49 +0000
changeset 2308 514f7c1651fc
parent 1895 c121d94672cb
child 2311 54e21acfec5a
permissions -rw-r--r--
Untested Win32 keyboard scancode code.
     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 void
    30 WIN_InitKeyboard(_THIS)
    31 {
    32     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    33     SDL_Keyboard keyboard;
    34 
    35     data->key_layout = win32_scancode_table;
    36 
    37     SDL_zero(keyboard);
    38     data->keyboard = SDL_AddKeyboard(&keyboard, -1);
    39     WIN_UpdateKeymap(_this);
    40 
    41     SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
    42     SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
    43     SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
    44 }
    45 
    46 void
    47 WIN_UpdateKeymap(_THIS)
    48 {
    49     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    50     int i;
    51     SDL_scancode scancode;
    52     SDLKey keymap[SDL_NUM_SCANCODES];
    53 
    54     SDL_GetDefaultKeymap(keymap);
    55 
    56     for (i = 0; i < SDL_arraysize(win32_scancode_table); i++) {
    57 
    58         /* Make sure this scancode is a valid character scancode */
    59         scancode = win32_scancode_table[i];
    60         if (scancode == SDL_SCANCODE_UNKNOWN ||
    61             (keymap[scancode] & SDLK_SCANCODE_MASK)) {
    62             continue;
    63         }
    64 #ifndef MAPVK_VK_TO_CHAR
    65 #define MAPVK_VK_TO_CHAR    2
    66 #endif
    67         keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
    68     }
    69     SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
    70 }
    71 
    72 void
    73 WIN_QuitKeyboard(_THIS)
    74 {
    75     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    76 
    77     SDL_DelKeyboard(data->keyboard);
    78 }
    79 
    80 /* vi: set ts=4 sw=4 expandtab: */