PageRenderTime 59ms CodeModel.GetById 37ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/project/jni/sdl-1.3/src/video/bwindow/SDL_bkeyboard.cc

https://github.com/aichunyu/FFPlayer
C++ | 189 lines | 151 code | 17 blank | 21 comment | 10 complexity | c8bfc9d2e0a30f79abca1b1058bde6ec MD5 | raw file
  1/*
  2    SDL - Simple DirectMedia Layer
  3    Copyright (C) 1997-2012 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#if SDL_VIDEO_DRIVER_BWINDOW
 25
 26#include <SupportDefs.h>
 27#include <support/UTF8.h>
 28
 29#ifdef __cplusplus
 30extern "C" {
 31#endif
 32
 33#include "SDL_events.h"
 34#include "SDL_keycode.h"
 35
 36#include "SDL_bkeyboard.h"
 37
 38
 39#define KEYMAP_SIZE 128
 40
 41
 42static SDL_Scancode keymap[KEYMAP_SIZE];
 43static int8 keystate[KEYMAP_SIZE];
 44
 45void BE_InitOSKeymap() {
 46		for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
 47			keymap[i] = SDL_SCANCODE_UNKNOWN;
 48		}
 49
 50		for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
 51			keystate[i] = SDL_RELEASED;
 52		}
 53
 54		keymap[0x01]		= SDL_GetScancodeFromKey(SDLK_ESCAPE);
 55		keymap[B_F1_KEY]	= SDL_GetScancodeFromKey(SDLK_F1);
 56		keymap[B_F2_KEY]	= SDL_GetScancodeFromKey(SDLK_F2);
 57		keymap[B_F3_KEY]	= SDL_GetScancodeFromKey(SDLK_F3);
 58		keymap[B_F4_KEY]	= SDL_GetScancodeFromKey(SDLK_F4);
 59		keymap[B_F5_KEY]	= SDL_GetScancodeFromKey(SDLK_F5);
 60		keymap[B_F6_KEY]	= SDL_GetScancodeFromKey(SDLK_F6);
 61		keymap[B_F7_KEY]	= SDL_GetScancodeFromKey(SDLK_F7);
 62		keymap[B_F8_KEY]	= SDL_GetScancodeFromKey(SDLK_F8);
 63		keymap[B_F9_KEY]	= SDL_GetScancodeFromKey(SDLK_F9);
 64		keymap[B_F10_KEY]	= SDL_GetScancodeFromKey(SDLK_F10);
 65		keymap[B_F11_KEY]	= SDL_GetScancodeFromKey(SDLK_F11);
 66		keymap[B_F12_KEY]	= SDL_GetScancodeFromKey(SDLK_F12);
 67		keymap[B_PRINT_KEY]	= SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
 68		keymap[B_SCROLL_KEY]	= SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
 69		keymap[B_PAUSE_KEY]	= SDL_GetScancodeFromKey(SDLK_PAUSE);
 70		keymap[0x11]		= SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
 71		keymap[0x12]		= SDL_GetScancodeFromKey(SDLK_1);
 72		keymap[0x13]		= SDL_GetScancodeFromKey(SDLK_2);
 73		keymap[0x14]		= SDL_GetScancodeFromKey(SDLK_3);
 74		keymap[0x15]		= SDL_GetScancodeFromKey(SDLK_4);
 75		keymap[0x16]		= SDL_GetScancodeFromKey(SDLK_5);
 76		keymap[0x17]		= SDL_GetScancodeFromKey(SDLK_6);
 77		keymap[0x18]		= SDL_GetScancodeFromKey(SDLK_7);
 78		keymap[0x19]		= SDL_GetScancodeFromKey(SDLK_8);
 79		keymap[0x1a]		= SDL_GetScancodeFromKey(SDLK_9);
 80		keymap[0x1b]		= SDL_GetScancodeFromKey(SDLK_0);
 81		keymap[0x1c]		= SDL_GetScancodeFromKey(SDLK_MINUS);
 82		keymap[0x1d]		= SDL_GetScancodeFromKey(SDLK_EQUALS);
 83		keymap[0x1e]		= SDL_GetScancodeFromKey(SDLK_BACKSPACE);
 84		keymap[0x1f]		= SDL_GetScancodeFromKey(SDLK_INSERT);
 85		keymap[0x20]		= SDL_GetScancodeFromKey(SDLK_HOME);
 86		keymap[0x21]		= SDL_GetScancodeFromKey(SDLK_PAGEUP);
 87		keymap[0x22]		= SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
 88		keymap[0x23]		= SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
 89		keymap[0x24]		= SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
 90		keymap[0x25]		= SDL_GetScancodeFromKey(SDLK_KP_MINUS);
 91		keymap[0x26]		= SDL_GetScancodeFromKey(SDLK_TAB);
 92		keymap[0x27]		= SDL_GetScancodeFromKey(SDLK_q);
 93		keymap[0x28]		= SDL_GetScancodeFromKey(SDLK_w);
 94		keymap[0x29]		= SDL_GetScancodeFromKey(SDLK_e);
 95		keymap[0x2a]		= SDL_GetScancodeFromKey(SDLK_r);
 96		keymap[0x2b]		= SDL_GetScancodeFromKey(SDLK_t);
 97		keymap[0x2c]		= SDL_GetScancodeFromKey(SDLK_y);
 98		keymap[0x2d]		= SDL_GetScancodeFromKey(SDLK_u);
 99		keymap[0x2e]		= SDL_GetScancodeFromKey(SDLK_i);
100		keymap[0x2f]		= SDL_GetScancodeFromKey(SDLK_o);
101		keymap[0x30]		= SDL_GetScancodeFromKey(SDLK_p);
102		keymap[0x31]		= SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
103		keymap[0x32]		= SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
104		keymap[0x33]		= SDL_GetScancodeFromKey(SDLK_BACKSLASH);
105		keymap[0x34]		= SDL_GetScancodeFromKey(SDLK_DELETE);
106		keymap[0x35]		= SDL_GetScancodeFromKey(SDLK_END);
107		keymap[0x36]		= SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
108		keymap[0x37]		= SDL_GetScancodeFromKey(SDLK_KP_7);
109		keymap[0x38]		= SDL_GetScancodeFromKey(SDLK_KP_8);
110		keymap[0x39]		= SDL_GetScancodeFromKey(SDLK_KP_9);
111		keymap[0x3a]		= SDL_GetScancodeFromKey(SDLK_KP_PLUS);
112		keymap[0x3b]		= SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
113		keymap[0x3c]		= SDL_GetScancodeFromKey(SDLK_a);
114		keymap[0x3d]		= SDL_GetScancodeFromKey(SDLK_s);
115		keymap[0x3e]		= SDL_GetScancodeFromKey(SDLK_d);
116		keymap[0x3f]		= SDL_GetScancodeFromKey(SDLK_f);
117		keymap[0x40]		= SDL_GetScancodeFromKey(SDLK_g);
118		keymap[0x41]		= SDL_GetScancodeFromKey(SDLK_h);
119		keymap[0x42]		= SDL_GetScancodeFromKey(SDLK_j);
120		keymap[0x43]		= SDL_GetScancodeFromKey(SDLK_k);
121		keymap[0x44]		= SDL_GetScancodeFromKey(SDLK_l);
122		keymap[0x45]		= SDL_GetScancodeFromKey(SDLK_SEMICOLON);
123		keymap[0x46]		= SDL_GetScancodeFromKey(SDLK_QUOTE);
124		keymap[0x47]		= SDL_GetScancodeFromKey(SDLK_RETURN);
125		keymap[0x48]		= SDL_GetScancodeFromKey(SDLK_KP_4);
126		keymap[0x49]		= SDL_GetScancodeFromKey(SDLK_KP_5);
127		keymap[0x4a]		= SDL_GetScancodeFromKey(SDLK_KP_6);
128		keymap[0x4b]		= SDL_GetScancodeFromKey(SDLK_LSHIFT);
129		keymap[0x4c]		= SDL_GetScancodeFromKey(SDLK_z);
130		keymap[0x4d]		= SDL_GetScancodeFromKey(SDLK_x);
131		keymap[0x4e]		= SDL_GetScancodeFromKey(SDLK_c);
132		keymap[0x4f]		= SDL_GetScancodeFromKey(SDLK_v);
133		keymap[0x50]		= SDL_GetScancodeFromKey(SDLK_b);
134		keymap[0x51]		= SDL_GetScancodeFromKey(SDLK_n);
135		keymap[0x52]		= SDL_GetScancodeFromKey(SDLK_m);
136		keymap[0x53]		= SDL_GetScancodeFromKey(SDLK_COMMA);
137		keymap[0x54]		= SDL_GetScancodeFromKey(SDLK_PERIOD);
138		keymap[0x55]		= SDL_GetScancodeFromKey(SDLK_SLASH);
139		keymap[0x56]		= SDL_GetScancodeFromKey(SDLK_RSHIFT);
140		keymap[0x57]		= SDL_GetScancodeFromKey(SDLK_UP);
141		keymap[0x58]		= SDL_GetScancodeFromKey(SDLK_KP_1);
142		keymap[0x59]		= SDL_GetScancodeFromKey(SDLK_KP_2);
143		keymap[0x5a]		= SDL_GetScancodeFromKey(SDLK_KP_3);
144		keymap[0x5b]		= SDL_GetScancodeFromKey(SDLK_KP_ENTER);
145		keymap[0x5c]		= SDL_GetScancodeFromKey(SDLK_LCTRL);
146		keymap[0x5d]		= SDL_GetScancodeFromKey(SDLK_LALT);
147		keymap[0x5e]		= SDL_GetScancodeFromKey(SDLK_SPACE);
148		keymap[0x5f]		= SDL_GetScancodeFromKey(SDLK_RALT);
149		keymap[0x60]		= SDL_GetScancodeFromKey(SDLK_RCTRL);
150		keymap[0x61]		= SDL_GetScancodeFromKey(SDLK_LEFT);
151		keymap[0x62]		= SDL_GetScancodeFromKey(SDLK_DOWN);
152		keymap[0x63]		= SDL_GetScancodeFromKey(SDLK_RIGHT);
153		keymap[0x64]		= SDL_GetScancodeFromKey(SDLK_KP_0);
154		keymap[0x65]		= SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
155		keymap[0x66]		= SDL_GetScancodeFromKey(SDLK_LGUI);
156		keymap[0x67]		= SDL_GetScancodeFromKey(SDLK_RGUI);
157		keymap[0x68]		= SDL_GetScancodeFromKey(SDLK_MENU);
158		keymap[0x69]		= SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
159		keymap[0x6a]		= SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
160		keymap[0x6b]		= SDL_GetScancodeFromKey(SDLK_POWER);
161}
162
163SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
164	if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) {
165		return keymap[bkey];
166	} else {
167		return SDL_SCANCODE_UNKNOWN;
168	}
169}
170
171int8 BE_GetKeyState(int32 bkey) {
172	if(bkey > 0 && bkey < KEYMAP_SIZE) {
173		return keystate[bkey];
174	} else {
175		return SDL_RELEASED;
176	}
177}
178
179void BE_SetKeyState(int32 bkey, int8 state) {
180	if(bkey > 0 && bkey < KEYMAP_SIZE) {
181		keystate[bkey] = state;
182	}
183}
184
185#ifdef __cplusplus
186}
187#endif
188
189#endif /* SDL_VIDEO_DRIVER_BWINDOW */