src/video/win32/SDL_win32keyboard.c
author dewyatt
Tue, 06 Jul 2010 02:34:49 -0400
changeset 4747 5284a3b3217a
parent 4465 3e69e077cb95
child 4748 d1ce08e2697f
permissions -rw-r--r--
Added empty text input functions for win32.
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 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@2311
    29
#ifndef MAPVK_VK_TO_VSC
slouken@2311
    30
#define MAPVK_VK_TO_VSC     0
slouken@2311
    31
#endif
slouken@2311
    32
#ifndef MAPVK_VSC_TO_VK
slouken@2311
    33
#define MAPVK_VSC_TO_VK     1
slouken@2311
    34
#endif
slouken@2311
    35
#ifndef MAPVK_VK_TO_CHAR
slouken@2311
    36
#define MAPVK_VK_TO_CHAR    2
slouken@2311
    37
#endif
slouken@2311
    38
slouken@2311
    39
/* Alphabetic scancodes for PC keyboards */
slouken@2311
    40
BYTE alpha_scancodes[26] = {
slouken@2311
    41
    30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
slouken@2311
    42
    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
slouken@2311
    43
};
slouken@2735
    44
slouken@2317
    45
BYTE keypad_scancodes[10] = {
slouken@2317
    46
    82, 79, 80, 81, 75, 76, 77, 71, 72, 73
slouken@2317
    47
};
slouken@2311
    48
slouken@1895
    49
void
slouken@1895
    50
WIN_InitKeyboard(_THIS)
slouken@1895
    51
{
slouken@1895
    52
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@2311
    53
    int i;
slouken@2311
    54
slouken@2311
    55
    /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
bob@2324
    56
    if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
slouken@2724
    57
#if 0
slouken@2726
    58
        printf
slouken@2726
    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");
slouken@2724
    60
#endif
slouken@2311
    61
        for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
bob@2324
    62
            alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
slouken@2724
    63
#if 0
bob@2324
    64
            printf("%d = %d\n", i, alpha_scancodes[i]);
slouken@2724
    65
#endif
slouken@2311
    66
        }
slouken@2311
    67
    }
slouken@2317
    68
    if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
slouken@2724
    69
#if 0
slouken@2726
    70
        printf
slouken@2726
    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");
slouken@2724
    72
#endif
slouken@2317
    73
        for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
bob@2324
    74
            keypad_scancodes[i] =
bob@2324
    75
                MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
slouken@2724
    76
#if 0
bob@2324
    77
            printf("%d = %d\n", i, keypad_scancodes[i]);
slouken@2724
    78
#endif
slouken@2317
    79
        }
slouken@2317
    80
    }
slouken@1895
    81
slouken@2308
    82
    data->key_layout = win32_scancode_table;
slouken@2308
    83
slouken@4465
    84
    WIN_UpdateKeymap();
slouken@2308
    85
slouken@2308
    86
    SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
slouken@2308
    87
    SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
slouken@2308
    88
    SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
slouken@2308
    89
}
slouken@2308
    90
slouken@2308
    91
void
slouken@4465
    92
WIN_UpdateKeymap()
slouken@2308
    93
{
slouken@2308
    94
    int i;
slouken@2308
    95
    SDL_scancode scancode;
slouken@2308
    96
    SDLKey keymap[SDL_NUM_SCANCODES];
slouken@2308
    97
slouken@2308
    98
    SDL_GetDefaultKeymap(keymap);
slouken@2308
    99
slouken@2308
   100
    for (i = 0; i < SDL_arraysize(win32_scancode_table); i++) {
slouken@2308
   101
slouken@2308
   102
        /* Make sure this scancode is a valid character scancode */
slouken@2308
   103
        scancode = win32_scancode_table[i];
slouken@2308
   104
        if (scancode == SDL_SCANCODE_UNKNOWN ||
slouken@2308
   105
            (keymap[scancode] & SDLK_SCANCODE_MASK)) {
slouken@2308
   106
            continue;
slouken@2308
   107
        }
slouken@2311
   108
slouken@2311
   109
        /* Alphabetic keys are handled specially, since Windows remaps them */
slouken@2311
   110
        if (i >= 'A' && i <= 'Z') {
bob@2324
   111
            BYTE vsc = alpha_scancodes[i - 'A'];
slouken@2311
   112
            keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20;
slouken@2311
   113
        } else {
slouken@2311
   114
            keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
slouken@2311
   115
        }
slouken@2308
   116
    }
slouken@4465
   117
    SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
slouken@1895
   118
}
slouken@1895
   119
slouken@1895
   120
void
slouken@1895
   121
WIN_QuitKeyboard(_THIS)
slouken@1895
   122
{
slouken@1895
   123
}
slouken@1895
   124
dewyatt@4747
   125
void
dewyatt@4747
   126
WIN_StartTextInput(_THIS)
dewyatt@4747
   127
{
dewyatt@4747
   128
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
dewyatt@4747
   129
dewyatt@4747
   130
}
dewyatt@4747
   131
dewyatt@4747
   132
void
dewyatt@4747
   133
WIN_StopTextInput(_THIS)
dewyatt@4747
   134
{
dewyatt@4747
   135
dewyatt@4747
   136
}
dewyatt@4747
   137
dewyatt@4747
   138
void
dewyatt@4747
   139
WIN_SetTextInputRect(_THIS, SDL_Rect *rect)
dewyatt@4747
   140
{
dewyatt@4747
   141
dewyatt@4747
   142
}
dewyatt@4747
   143
slouken@1895
   144
/* vi: set ts=4 sw=4 expandtab: */