src/video/bwindow/SDL_bkeyboard.cc
author Nathan Heisey <nathanheisey@gmail.com>
Thu, 28 Jul 2011 18:21:38 +0000
changeset 5930 a2372d470620
parent 5928 a3a52295bc0d
child 6037 2feab4874268
permissions -rw-r--r--
Render thread partially corrected
nathanheisey@5928
     1
/*
nathanheisey@5928
     2
    SDL - Simple DirectMedia Layer
nathanheisey@5928
     3
    Copyright (C) 1997-2009 Sam Lantinga
nathanheisey@5928
     4
nathanheisey@5928
     5
    This library is free software; you can redistribute it and/or
nathanheisey@5928
     6
    modify it under the terms of the GNU Lesser General Public
nathanheisey@5928
     7
    License as published by the Free Software Foundation; either
nathanheisey@5928
     8
    version 2.1 of the License, or (at your option) any later version.
nathanheisey@5928
     9
nathanheisey@5928
    10
    This library is distributed in the hope that it will be useful,
nathanheisey@5928
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
nathanheisey@5928
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nathanheisey@5928
    13
    Lesser General Public License for more details.
nathanheisey@5928
    14
nathanheisey@5928
    15
    You should have received a copy of the GNU Lesser General Public
nathanheisey@5928
    16
    License along with this library; if not, write to the Free Software
nathanheisey@5928
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
nathanheisey@5928
    18
nathanheisey@5928
    19
    Sam Lantinga
nathanheisey@5928
    20
    slouken@libsdl.org
nathanheisey@5928
    21
*/
nathanheisey@5928
    22
nathanheisey@5928
    23
#include <SupportDefs.h>
nathanheisey@5928
    24
#include <support/UTF8.h>
nathanheisey@5928
    25
nathanheisey@5928
    26
#ifdef __cplusplus
nathanheisey@5928
    27
extern "C" {
nathanheisey@5928
    28
#endif
nathanheisey@5928
    29
nathanheisey@5928
    30
#include "SDL_events.h"
nathanheisey@5928
    31
#include "SDL_keycode.h"
nathanheisey@5928
    32
nathanheisey@5928
    33
#include "SDL_bkeyboard.h"
nathanheisey@5928
    34
nathanheisey@5928
    35
nathanheisey@5928
    36
#define KEYMAP_SIZE 128
nathanheisey@5928
    37
nathanheisey@5928
    38
nathanheisey@5928
    39
static SDL_Scancode keymap[KEYMAP_SIZE];
nathanheisey@5928
    40
static int8 keystate[KEYMAP_SIZE];
nathanheisey@5928
    41
nathanheisey@5928
    42
void BE_InitOSKeymap() {
nathanheisey@5928
    43
		for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
nathanheisey@5928
    44
			keymap[i] = SDL_SCANCODE_UNKNOWN;
nathanheisey@5928
    45
		}
nathanheisey@5928
    46
nathanheisey@5928
    47
		for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
nathanheisey@5928
    48
			keystate[i] = SDL_RELEASED;
nathanheisey@5928
    49
		}
nathanheisey@5928
    50
nathanheisey@5928
    51
		keymap[0x01]		= SDL_GetScancodeFromKey(SDLK_ESCAPE);
nathanheisey@5928
    52
		keymap[B_F1_KEY]	= SDL_GetScancodeFromKey(SDLK_F1);
nathanheisey@5928
    53
		keymap[B_F2_KEY]	= SDL_GetScancodeFromKey(SDLK_F2);
nathanheisey@5928
    54
		keymap[B_F3_KEY]	= SDL_GetScancodeFromKey(SDLK_F3);
nathanheisey@5928
    55
		keymap[B_F4_KEY]	= SDL_GetScancodeFromKey(SDLK_F4);
nathanheisey@5928
    56
		keymap[B_F5_KEY]	= SDL_GetScancodeFromKey(SDLK_F5);
nathanheisey@5928
    57
		keymap[B_F6_KEY]	= SDL_GetScancodeFromKey(SDLK_F6);
nathanheisey@5928
    58
		keymap[B_F7_KEY]	= SDL_GetScancodeFromKey(SDLK_F7);
nathanheisey@5928
    59
		keymap[B_F8_KEY]	= SDL_GetScancodeFromKey(SDLK_F8);
nathanheisey@5928
    60
		keymap[B_F9_KEY]	= SDL_GetScancodeFromKey(SDLK_F9);
nathanheisey@5928
    61
		keymap[B_F10_KEY]	= SDL_GetScancodeFromKey(SDLK_F10);
nathanheisey@5928
    62
		keymap[B_F11_KEY]	= SDL_GetScancodeFromKey(SDLK_F11);
nathanheisey@5928
    63
		keymap[B_F12_KEY]	= SDL_GetScancodeFromKey(SDLK_F12);
nathanheisey@5928
    64
		keymap[B_PRINT_KEY]	= SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
nathanheisey@5928
    65
		keymap[B_SCROLL_KEY]	= SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
nathanheisey@5928
    66
		keymap[B_PAUSE_KEY]	= SDL_GetScancodeFromKey(SDLK_PAUSE);
nathanheisey@5928
    67
		keymap[0x11]		= SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
nathanheisey@5928
    68
		keymap[0x12]		= SDL_GetScancodeFromKey(SDLK_1);
nathanheisey@5928
    69
		keymap[0x13]		= SDL_GetScancodeFromKey(SDLK_2);
nathanheisey@5928
    70
		keymap[0x14]		= SDL_GetScancodeFromKey(SDLK_3);
nathanheisey@5928
    71
		keymap[0x15]		= SDL_GetScancodeFromKey(SDLK_4);
nathanheisey@5928
    72
		keymap[0x16]		= SDL_GetScancodeFromKey(SDLK_5);
nathanheisey@5928
    73
		keymap[0x17]		= SDL_GetScancodeFromKey(SDLK_6);
nathanheisey@5928
    74
		keymap[0x18]		= SDL_GetScancodeFromKey(SDLK_7);
nathanheisey@5928
    75
		keymap[0x19]		= SDL_GetScancodeFromKey(SDLK_8);
nathanheisey@5928
    76
		keymap[0x1a]		= SDL_GetScancodeFromKey(SDLK_9);
nathanheisey@5928
    77
		keymap[0x1b]		= SDL_GetScancodeFromKey(SDLK_0);
nathanheisey@5928
    78
		keymap[0x1c]		= SDL_GetScancodeFromKey(SDLK_MINUS);
nathanheisey@5928
    79
		keymap[0x1d]		= SDL_GetScancodeFromKey(SDLK_EQUALS);
nathanheisey@5928
    80
		keymap[0x1e]		= SDL_GetScancodeFromKey(SDLK_BACKSPACE);
nathanheisey@5928
    81
		keymap[0x1f]		= SDL_GetScancodeFromKey(SDLK_INSERT);
nathanheisey@5928
    82
		keymap[0x20]		= SDL_GetScancodeFromKey(SDLK_HOME);
nathanheisey@5928
    83
		keymap[0x21]		= SDL_GetScancodeFromKey(SDLK_PAGEUP);
nathanheisey@5928
    84
		keymap[0x22]		= SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
nathanheisey@5928
    85
		keymap[0x23]		= SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
nathanheisey@5928
    86
		keymap[0x24]		= SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
nathanheisey@5928
    87
		keymap[0x25]		= SDL_GetScancodeFromKey(SDLK_KP_MINUS);
nathanheisey@5928
    88
		keymap[0x26]		= SDL_GetScancodeFromKey(SDLK_TAB);
nathanheisey@5928
    89
		keymap[0x27]		= SDL_GetScancodeFromKey(SDLK_q);
nathanheisey@5928
    90
		keymap[0x28]		= SDL_GetScancodeFromKey(SDLK_w);
nathanheisey@5928
    91
		keymap[0x29]		= SDL_GetScancodeFromKey(SDLK_e);
nathanheisey@5928
    92
		keymap[0x2a]		= SDL_GetScancodeFromKey(SDLK_r);
nathanheisey@5928
    93
		keymap[0x2b]		= SDL_GetScancodeFromKey(SDLK_t);
nathanheisey@5928
    94
		keymap[0x2c]		= SDL_GetScancodeFromKey(SDLK_y);
nathanheisey@5928
    95
		keymap[0x2d]		= SDL_GetScancodeFromKey(SDLK_u);
nathanheisey@5928
    96
		keymap[0x2e]		= SDL_GetScancodeFromKey(SDLK_i);
nathanheisey@5928
    97
		keymap[0x2f]		= SDL_GetScancodeFromKey(SDLK_o);
nathanheisey@5928
    98
		keymap[0x30]		= SDL_GetScancodeFromKey(SDLK_p);
nathanheisey@5928
    99
		keymap[0x31]		= SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
nathanheisey@5928
   100
		keymap[0x32]		= SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
nathanheisey@5928
   101
		keymap[0x33]		= SDL_GetScancodeFromKey(SDLK_BACKSLASH);
nathanheisey@5928
   102
		keymap[0x34]		= SDL_GetScancodeFromKey(SDLK_DELETE);
nathanheisey@5928
   103
		keymap[0x35]		= SDL_GetScancodeFromKey(SDLK_END);
nathanheisey@5928
   104
		keymap[0x36]		= SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
nathanheisey@5928
   105
		keymap[0x37]		= SDL_GetScancodeFromKey(SDLK_KP_7);
nathanheisey@5928
   106
		keymap[0x38]		= SDL_GetScancodeFromKey(SDLK_KP_8);
nathanheisey@5928
   107
		keymap[0x39]		= SDL_GetScancodeFromKey(SDLK_KP_9);
nathanheisey@5928
   108
		keymap[0x3a]		= SDL_GetScancodeFromKey(SDLK_KP_PLUS);
nathanheisey@5928
   109
		keymap[0x3b]		= SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
nathanheisey@5928
   110
		keymap[0x3c]		= SDL_GetScancodeFromKey(SDLK_a);
nathanheisey@5928
   111
		keymap[0x3d]		= SDL_GetScancodeFromKey(SDLK_s);
nathanheisey@5928
   112
		keymap[0x3e]		= SDL_GetScancodeFromKey(SDLK_d);
nathanheisey@5928
   113
		keymap[0x3f]		= SDL_GetScancodeFromKey(SDLK_f);
nathanheisey@5928
   114
		keymap[0x40]		= SDL_GetScancodeFromKey(SDLK_g);
nathanheisey@5928
   115
		keymap[0x41]		= SDL_GetScancodeFromKey(SDLK_h);
nathanheisey@5928
   116
		keymap[0x42]		= SDL_GetScancodeFromKey(SDLK_j);
nathanheisey@5928
   117
		keymap[0x43]		= SDL_GetScancodeFromKey(SDLK_k);
nathanheisey@5928
   118
		keymap[0x44]		= SDL_GetScancodeFromKey(SDLK_l);
nathanheisey@5928
   119
		keymap[0x45]		= SDL_GetScancodeFromKey(SDLK_SEMICOLON);
nathanheisey@5928
   120
		keymap[0x46]		= SDL_GetScancodeFromKey(SDLK_QUOTE);
nathanheisey@5928
   121
		keymap[0x47]		= SDL_GetScancodeFromKey(SDLK_RETURN);
nathanheisey@5928
   122
		keymap[0x48]		= SDL_GetScancodeFromKey(SDLK_KP_4);
nathanheisey@5928
   123
		keymap[0x49]		= SDL_GetScancodeFromKey(SDLK_KP_5);
nathanheisey@5928
   124
		keymap[0x4a]		= SDL_GetScancodeFromKey(SDLK_KP_6);
nathanheisey@5928
   125
		keymap[0x4b]		= SDL_GetScancodeFromKey(SDLK_LSHIFT);
nathanheisey@5928
   126
		keymap[0x4c]		= SDL_GetScancodeFromKey(SDLK_z);
nathanheisey@5928
   127
		keymap[0x4d]		= SDL_GetScancodeFromKey(SDLK_x);
nathanheisey@5928
   128
		keymap[0x4e]		= SDL_GetScancodeFromKey(SDLK_c);
nathanheisey@5928
   129
		keymap[0x4f]		= SDL_GetScancodeFromKey(SDLK_v);
nathanheisey@5928
   130
		keymap[0x50]		= SDL_GetScancodeFromKey(SDLK_b);
nathanheisey@5928
   131
		keymap[0x51]		= SDL_GetScancodeFromKey(SDLK_n);
nathanheisey@5928
   132
		keymap[0x52]		= SDL_GetScancodeFromKey(SDLK_m);
nathanheisey@5928
   133
		keymap[0x53]		= SDL_GetScancodeFromKey(SDLK_COMMA);
nathanheisey@5928
   134
		keymap[0x54]		= SDL_GetScancodeFromKey(SDLK_PERIOD);
nathanheisey@5928
   135
		keymap[0x55]		= SDL_GetScancodeFromKey(SDLK_SLASH);
nathanheisey@5928
   136
		keymap[0x56]		= SDL_GetScancodeFromKey(SDLK_RSHIFT);
nathanheisey@5928
   137
		keymap[0x57]		= SDL_GetScancodeFromKey(SDLK_UP);
nathanheisey@5928
   138
		keymap[0x58]		= SDL_GetScancodeFromKey(SDLK_KP_1);
nathanheisey@5928
   139
		keymap[0x59]		= SDL_GetScancodeFromKey(SDLK_KP_2);
nathanheisey@5928
   140
		keymap[0x5a]		= SDL_GetScancodeFromKey(SDLK_KP_3);
nathanheisey@5928
   141
		keymap[0x5b]		= SDL_GetScancodeFromKey(SDLK_KP_ENTER);
nathanheisey@5928
   142
		keymap[0x5c]		= SDL_GetScancodeFromKey(SDLK_LCTRL);
nathanheisey@5928
   143
		keymap[0x5d]		= SDL_GetScancodeFromKey(SDLK_LALT);
nathanheisey@5928
   144
		keymap[0x5e]		= SDL_GetScancodeFromKey(SDLK_SPACE);
nathanheisey@5928
   145
		keymap[0x5f]		= SDL_GetScancodeFromKey(SDLK_RALT);
nathanheisey@5928
   146
		keymap[0x60]		= SDL_GetScancodeFromKey(SDLK_RCTRL);
nathanheisey@5928
   147
		keymap[0x61]		= SDL_GetScancodeFromKey(SDLK_LEFT);
nathanheisey@5928
   148
		keymap[0x62]		= SDL_GetScancodeFromKey(SDLK_DOWN);
nathanheisey@5928
   149
		keymap[0x63]		= SDL_GetScancodeFromKey(SDLK_RIGHT);
nathanheisey@5928
   150
		keymap[0x64]		= SDL_GetScancodeFromKey(SDLK_KP_0);
nathanheisey@5928
   151
		keymap[0x65]		= SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
nathanheisey@5930
   152
		keymap[0x66]		= SDL_GetScancodeFromKey(SDLK_LGUI);
nathanheisey@5930
   153
		keymap[0x67]		= SDL_GetScancodeFromKey(SDLK_RGUI);
nathanheisey@5928
   154
		keymap[0x68]		= SDL_GetScancodeFromKey(SDLK_MENU);
nathanheisey@5930
   155
		keymap[0x69]		= SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
nathanheisey@5928
   156
		keymap[0x6a]		= SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
nathanheisey@5928
   157
		keymap[0x6b]		= SDL_GetScancodeFromKey(SDLK_POWER);
nathanheisey@5928
   158
}
nathanheisey@5928
   159
nathanheisey@5928
   160
SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
nathanheisey@5928
   161
	if(bkey > 0 && bkey < SDL_TABLESIZE(keymap)) {
nathanheisey@5928
   162
		return keymap[bkey];
nathanheisey@5928
   163
	} else {
nathanheisey@5928
   164
		return SDL_SCANCODE_UNKNOWN;
nathanheisey@5928
   165
	}
nathanheisey@5928
   166
}
nathanheisey@5928
   167
nathanheisey@5928
   168
int8 BE_GetKeyState(int32 bkey) {
nathanheisey@5928
   169
	if(bkey > 0 && bkey < KEYMAP_SIZE) {
nathanheisey@5928
   170
		return keystate[bkey];
nathanheisey@5928
   171
	} else {
nathanheisey@5928
   172
		return SDL_RELEASED;
nathanheisey@5928
   173
	}
nathanheisey@5928
   174
}
nathanheisey@5928
   175
nathanheisey@5928
   176
void BE_SetKeyState(int32 bkey, int8 state) {
nathanheisey@5928
   177
	if(bkey > 0 && bkey < KEYMAP_SIZE) {
nathanheisey@5928
   178
		keystate[bkey] = state;
nathanheisey@5928
   179
	}
nathanheisey@5928
   180
}
nathanheisey@5928
   181
nathanheisey@5928
   182
#ifdef __cplusplus
nathanheisey@5928
   183
}
nathanheisey@5928
   184
#endif