• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 
5   This software is provided 'as-is', without any express or implied
6   warranty.  In no event will the authors be held liable for any damages
7   arising from the use of this software.
8 
9   Permission is granted to anyone to use this software for any purpose,
10   including commercial applications, and to alter it and redistribute it
11   freely, subject to the following restrictions:
12 
13   1. The origin of this software must not be misrepresented; you must not
14      claim that you wrote the original software. If you use this software
15      in a product, an acknowledgment in the product documentation would be
16      appreciated but is not required.
17   2. Altered source versions must be plainly marked as such, and must not be
18      misrepresented as being the original software.
19   3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #if SDL_VIDEO_DRIVER_HAIKU
24 
25 #include <SupportDefs.h>
26 #include <support/UTF8.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include "SDL_events.h"
33 #include "SDL_keycode.h"
34 
35 #include "SDL_bkeyboard.h"
36 
37 
38 #define KEYMAP_SIZE 128
39 
40 
41 static SDL_Scancode keymap[KEYMAP_SIZE];
42 static int8 keystate[KEYMAP_SIZE];
43 
BE_InitOSKeymap()44 void BE_InitOSKeymap() {
45 		for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
46 			keymap[i] = SDL_SCANCODE_UNKNOWN;
47 		}
48 
49 		for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
50 			keystate[i] = SDL_RELEASED;
51 		}
52 
53 		keymap[0x01]		= SDL_GetScancodeFromKey(SDLK_ESCAPE);
54 		keymap[B_F1_KEY]	= SDL_GetScancodeFromKey(SDLK_F1);
55 		keymap[B_F2_KEY]	= SDL_GetScancodeFromKey(SDLK_F2);
56 		keymap[B_F3_KEY]	= SDL_GetScancodeFromKey(SDLK_F3);
57 		keymap[B_F4_KEY]	= SDL_GetScancodeFromKey(SDLK_F4);
58 		keymap[B_F5_KEY]	= SDL_GetScancodeFromKey(SDLK_F5);
59 		keymap[B_F6_KEY]	= SDL_GetScancodeFromKey(SDLK_F6);
60 		keymap[B_F7_KEY]	= SDL_GetScancodeFromKey(SDLK_F7);
61 		keymap[B_F8_KEY]	= SDL_GetScancodeFromKey(SDLK_F8);
62 		keymap[B_F9_KEY]	= SDL_GetScancodeFromKey(SDLK_F9);
63 		keymap[B_F10_KEY]	= SDL_GetScancodeFromKey(SDLK_F10);
64 		keymap[B_F11_KEY]	= SDL_GetScancodeFromKey(SDLK_F11);
65 		keymap[B_F12_KEY]	= SDL_GetScancodeFromKey(SDLK_F12);
66 		keymap[B_PRINT_KEY]	= SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
67 		keymap[B_SCROLL_KEY]	= SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
68 		keymap[B_PAUSE_KEY]	= SDL_GetScancodeFromKey(SDLK_PAUSE);
69 		keymap[0x11]		= SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
70 		keymap[0x12]		= SDL_GetScancodeFromKey(SDLK_1);
71 		keymap[0x13]		= SDL_GetScancodeFromKey(SDLK_2);
72 		keymap[0x14]		= SDL_GetScancodeFromKey(SDLK_3);
73 		keymap[0x15]		= SDL_GetScancodeFromKey(SDLK_4);
74 		keymap[0x16]		= SDL_GetScancodeFromKey(SDLK_5);
75 		keymap[0x17]		= SDL_GetScancodeFromKey(SDLK_6);
76 		keymap[0x18]		= SDL_GetScancodeFromKey(SDLK_7);
77 		keymap[0x19]		= SDL_GetScancodeFromKey(SDLK_8);
78 		keymap[0x1a]		= SDL_GetScancodeFromKey(SDLK_9);
79 		keymap[0x1b]		= SDL_GetScancodeFromKey(SDLK_0);
80 		keymap[0x1c]		= SDL_GetScancodeFromKey(SDLK_MINUS);
81 		keymap[0x1d]		= SDL_GetScancodeFromKey(SDLK_EQUALS);
82 		keymap[0x1e]		= SDL_GetScancodeFromKey(SDLK_BACKSPACE);
83 		keymap[0x1f]		= SDL_GetScancodeFromKey(SDLK_INSERT);
84 		keymap[0x20]		= SDL_GetScancodeFromKey(SDLK_HOME);
85 		keymap[0x21]		= SDL_GetScancodeFromKey(SDLK_PAGEUP);
86 		keymap[0x22]		= SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
87 		keymap[0x23]		= SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
88 		keymap[0x24]		= SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
89 		keymap[0x25]		= SDL_GetScancodeFromKey(SDLK_KP_MINUS);
90 		keymap[0x26]		= SDL_GetScancodeFromKey(SDLK_TAB);
91 		keymap[0x27]		= SDL_GetScancodeFromKey(SDLK_q);
92 		keymap[0x28]		= SDL_GetScancodeFromKey(SDLK_w);
93 		keymap[0x29]		= SDL_GetScancodeFromKey(SDLK_e);
94 		keymap[0x2a]		= SDL_GetScancodeFromKey(SDLK_r);
95 		keymap[0x2b]		= SDL_GetScancodeFromKey(SDLK_t);
96 		keymap[0x2c]		= SDL_GetScancodeFromKey(SDLK_y);
97 		keymap[0x2d]		= SDL_GetScancodeFromKey(SDLK_u);
98 		keymap[0x2e]		= SDL_GetScancodeFromKey(SDLK_i);
99 		keymap[0x2f]		= SDL_GetScancodeFromKey(SDLK_o);
100 		keymap[0x30]		= SDL_GetScancodeFromKey(SDLK_p);
101 		keymap[0x31]		= SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
102 		keymap[0x32]		= SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
103 		keymap[0x33]		= SDL_GetScancodeFromKey(SDLK_BACKSLASH);
104 		keymap[0x34]		= SDL_GetScancodeFromKey(SDLK_DELETE);
105 		keymap[0x35]		= SDL_GetScancodeFromKey(SDLK_END);
106 		keymap[0x36]		= SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
107 		keymap[0x37]		= SDL_GetScancodeFromKey(SDLK_KP_7);
108 		keymap[0x38]		= SDL_GetScancodeFromKey(SDLK_KP_8);
109 		keymap[0x39]		= SDL_GetScancodeFromKey(SDLK_KP_9);
110 		keymap[0x3a]		= SDL_GetScancodeFromKey(SDLK_KP_PLUS);
111 		keymap[0x3b]		= SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
112 		keymap[0x3c]		= SDL_GetScancodeFromKey(SDLK_a);
113 		keymap[0x3d]		= SDL_GetScancodeFromKey(SDLK_s);
114 		keymap[0x3e]		= SDL_GetScancodeFromKey(SDLK_d);
115 		keymap[0x3f]		= SDL_GetScancodeFromKey(SDLK_f);
116 		keymap[0x40]		= SDL_GetScancodeFromKey(SDLK_g);
117 		keymap[0x41]		= SDL_GetScancodeFromKey(SDLK_h);
118 		keymap[0x42]		= SDL_GetScancodeFromKey(SDLK_j);
119 		keymap[0x43]		= SDL_GetScancodeFromKey(SDLK_k);
120 		keymap[0x44]		= SDL_GetScancodeFromKey(SDLK_l);
121 		keymap[0x45]		= SDL_GetScancodeFromKey(SDLK_SEMICOLON);
122 		keymap[0x46]		= SDL_GetScancodeFromKey(SDLK_QUOTE);
123 		keymap[0x47]		= SDL_GetScancodeFromKey(SDLK_RETURN);
124 		keymap[0x48]		= SDL_GetScancodeFromKey(SDLK_KP_4);
125 		keymap[0x49]		= SDL_GetScancodeFromKey(SDLK_KP_5);
126 		keymap[0x4a]		= SDL_GetScancodeFromKey(SDLK_KP_6);
127 		keymap[0x4b]		= SDL_GetScancodeFromKey(SDLK_LSHIFT);
128 		keymap[0x4c]		= SDL_GetScancodeFromKey(SDLK_z);
129 		keymap[0x4d]		= SDL_GetScancodeFromKey(SDLK_x);
130 		keymap[0x4e]		= SDL_GetScancodeFromKey(SDLK_c);
131 		keymap[0x4f]		= SDL_GetScancodeFromKey(SDLK_v);
132 		keymap[0x50]		= SDL_GetScancodeFromKey(SDLK_b);
133 		keymap[0x51]		= SDL_GetScancodeFromKey(SDLK_n);
134 		keymap[0x52]		= SDL_GetScancodeFromKey(SDLK_m);
135 		keymap[0x53]		= SDL_GetScancodeFromKey(SDLK_COMMA);
136 		keymap[0x54]		= SDL_GetScancodeFromKey(SDLK_PERIOD);
137 		keymap[0x55]		= SDL_GetScancodeFromKey(SDLK_SLASH);
138 		keymap[0x56]		= SDL_GetScancodeFromKey(SDLK_RSHIFT);
139 		keymap[0x57]		= SDL_GetScancodeFromKey(SDLK_UP);
140 		keymap[0x58]		= SDL_GetScancodeFromKey(SDLK_KP_1);
141 		keymap[0x59]		= SDL_GetScancodeFromKey(SDLK_KP_2);
142 		keymap[0x5a]		= SDL_GetScancodeFromKey(SDLK_KP_3);
143 		keymap[0x5b]		= SDL_GetScancodeFromKey(SDLK_KP_ENTER);
144 		keymap[0x5c]		= SDL_GetScancodeFromKey(SDLK_LCTRL);
145 		keymap[0x5d]		= SDL_GetScancodeFromKey(SDLK_LALT);
146 		keymap[0x5e]		= SDL_GetScancodeFromKey(SDLK_SPACE);
147 		keymap[0x5f]		= SDL_GetScancodeFromKey(SDLK_RALT);
148 		keymap[0x60]		= SDL_GetScancodeFromKey(SDLK_RCTRL);
149 		keymap[0x61]		= SDL_GetScancodeFromKey(SDLK_LEFT);
150 		keymap[0x62]		= SDL_GetScancodeFromKey(SDLK_DOWN);
151 		keymap[0x63]		= SDL_GetScancodeFromKey(SDLK_RIGHT);
152 		keymap[0x64]		= SDL_GetScancodeFromKey(SDLK_KP_0);
153 		keymap[0x65]		= SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
154 		keymap[0x66]		= SDL_GetScancodeFromKey(SDLK_LGUI);
155 		keymap[0x67]		= SDL_GetScancodeFromKey(SDLK_RGUI);
156 		keymap[0x68]		= SDL_GetScancodeFromKey(SDLK_MENU);
157 		keymap[0x69]		= SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
158 		keymap[0x6a]		= SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
159 		keymap[0x6b]		= SDL_GetScancodeFromKey(SDLK_POWER);
160 }
161 
BE_GetScancodeFromBeKey(int32 bkey)162 SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
163 	if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) {
164 		return keymap[bkey];
165 	} else {
166 		return SDL_SCANCODE_UNKNOWN;
167 	}
168 }
169 
BE_GetKeyState(int32 bkey)170 int8 BE_GetKeyState(int32 bkey) {
171 	if(bkey > 0 && bkey < KEYMAP_SIZE) {
172 		return keystate[bkey];
173 	} else {
174 		return SDL_RELEASED;
175 	}
176 }
177 
BE_SetKeyState(int32 bkey,int8 state)178 void BE_SetKeyState(int32 bkey, int8 state) {
179 	if(bkey > 0 && bkey < KEYMAP_SIZE) {
180 		keystate[bkey] = state;
181 	}
182 }
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif /* SDL_VIDEO_DRIVER_HAIKU */
189