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.
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@1895
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1895
     4
slouken@1895
     5
    This library is free software; you can redistribute it and/or
slouken@1895
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1895
     7
    License as published by the Free Software Foundation; either
slouken@1895
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1895
     9
slouken@1895
    10
    This library is distributed in the hope that it will be useful,
slouken@1895
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1895
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1895
    13
    Lesser General Public License for more details.
slouken@1895
    14
slouken@1895
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1895
    16
    License along with this library; if not, write to the Free Software
slouken@1895
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1895
    18
slouken@1895
    19
    Sam Lantinga
slouken@1895
    20
    slouken@libsdl.org
slouken@1895
    21
*/
slouken@1895
    22
#include "SDL_config.h"
slouken@1895
    23
slouken@1895
    24
#include "SDL_win32video.h"
slouken@1895
    25
slouken@1895
    26
#include "../../events/SDL_keyboard_c.h"
slouken@2308
    27
#include "../../events/scancodes_win32.h"
slouken@1895
    28
slouken@1895
    29
void
slouken@1895
    30
WIN_InitKeyboard(_THIS)
slouken@1895
    31
{
slouken@1895
    32
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1895
    33
    SDL_Keyboard keyboard;
slouken@1895
    34
slouken@2308
    35
    data->key_layout = win32_scancode_table;
slouken@2308
    36
slouken@1895
    37
    SDL_zero(keyboard);
slouken@1895
    38
    data->keyboard = SDL_AddKeyboard(&keyboard, -1);
slouken@2308
    39
    WIN_UpdateKeymap(_this);
slouken@2308
    40
slouken@2308
    41
    SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
slouken@2308
    42
    SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
slouken@2308
    43
    SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
slouken@2308
    44
}
slouken@2308
    45
slouken@2308
    46
void
slouken@2308
    47
WIN_UpdateKeymap(_THIS)
slouken@2308
    48
{
slouken@2308
    49
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@2308
    50
    int i;
slouken@2308
    51
    SDL_scancode scancode;
slouken@2308
    52
    SDLKey keymap[SDL_NUM_SCANCODES];
slouken@2308
    53
slouken@2308
    54
    SDL_GetDefaultKeymap(keymap);
slouken@2308
    55
slouken@2308
    56
    for (i = 0; i < SDL_arraysize(win32_scancode_table); i++) {
slouken@2308
    57
slouken@2308
    58
        /* Make sure this scancode is a valid character scancode */
slouken@2308
    59
        scancode = win32_scancode_table[i];
slouken@2308
    60
        if (scancode == SDL_SCANCODE_UNKNOWN ||
slouken@2308
    61
            (keymap[scancode] & SDLK_SCANCODE_MASK)) {
slouken@2308
    62
            continue;
slouken@2308
    63
        }
slouken@2308
    64
#ifndef MAPVK_VK_TO_CHAR
slouken@2308
    65
#define MAPVK_VK_TO_CHAR    2
slouken@2308
    66
#endif
slouken@2308
    67
        keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
slouken@2308
    68
    }
slouken@2308
    69
    SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
slouken@1895
    70
}
slouken@1895
    71
slouken@1895
    72
void
slouken@1895
    73
WIN_QuitKeyboard(_THIS)
slouken@1895
    74
{
slouken@1895
    75
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1895
    76
slouken@1895
    77
    SDL_DelKeyboard(data->keyboard);
slouken@1895
    78
}
slouken@1895
    79
slouken@1895
    80
/* vi: set ts=4 sw=4 expandtab: */