Wed, 29 Dec 2010 09:04:43 +0000
merge heads (properly this time)
1 #include "SDL.h"
3 /**
4 * Key map -- a mapping from SDLK_xxx constants to scancodes and vice versa.
5 */
6 struct {
7 SDLKey key; ///< SDLK_xxx key code constant
8 int extended; ///< 1 if this is an extended keycode
9 unsigned char scancode; ///< Keyboard scan code
10 } keymap[] = {
11 { SDLK_UP, 0, 0x01 }, // ROLL/Up [UpArrow]
12 { SDLK_KP2, 0, 0x01 }, // ROLL/Up [Keypad 2]
13 // { SDLK_, 1, 0x02 }, // Clear Line
14 // { SDLK_, 1, 0x03 }, // Rstrt / Ref
15 // { SDLK_, 1, 0x04 }, // Exit
16 { SDLK_KP1, 0, 0x05 }, // PREV [Keypad 1]
17 // { SDLK_, 1, 0x06 }, // Msg
18 // { SDLK_, 1, 0x07 }, // Cancl
19 { SDLK_BACKSPACE, 0, 0x08 }, // Backspace
20 { SDLK_TAB, 0, 0x09 }, // Tab
21 // { SDLK_RETURN, 1, 0x0a }, // ENTER
22 { SDLK_DOWN, 0, 0x0b }, // ROLL/Down [DownArrow]
23 { SDLK_KP0, 0, 0x0b }, // ROLL/Down [Keypad 0]
24 { SDLK_KP3, 0, 0x0c }, // NEXT [Keypad 3]
25 { SDLK_RETURN, 0, 0x0d }, // RETURN [Return]
26 { SDLK_LEFT, 0, 0x0e }, // <-- [LeftArrow]
27 { SDLK_KP_MINUS, 0, 0x0e }, // <-- [Keypad -]
28 { SDLK_RIGHT, 0, 0x0f }, // --> [RightArrow]
29 { SDLK_KP_PERIOD, 0, 0x0f }, // --> [Keypad .]
30 // { SDLK_, 1, 0x10 }, // Creat
31 // { SDLK_, 1, 0x11 }, // Save
32 // { SDLK_, 1, 0x12 }, // Move
33 // { SDLK_, 1, 0x13 }, // Ops
34 // { SDLK_, 1, 0x14 }, // Copy
35 { SDLK_F1, 0, 0x15 }, // F1
36 { SDLK_F2, 0, 0x16 }, // F2
37 { SDLK_F3, 0, 0x17 }, // F3
38 { SDLK_F4, 0, 0x18 }, // F4
39 { SDLK_F5, 0, 0x19 }, // F5
40 { SDLK_F6, 0, 0x1a }, // F6
41 { SDLK_ESCAPE, 0, 0x1b }, // ESC/DEL [Escape]
42 { SDLK_F7, 0, 0x1c }, // F7
43 { SDLK_F8, 0, 0x1d }, // F8
44 // { SDLK_, 1, 0x1e }, // Suspd
45 // { SDLK_, 1, 0x1f }, // Rsume
46 { SDLK_SPACE, 0, 0x20 }, // SPACE [Spacebar]
47 // { SDLK_, 1, 0x21 }, // Undo
48 // { SDLK_, 1, 0x22 }, // Redo
49 // { SDLK_, 1, 0x23 }, // FIND
50 // { SDLK_, 1, 0x24 }, // RPLAC
51 { SDLK_BREAK, 0, 0x25 }, // RESET/BREAK [Pause/Break]
52 // { SDLK_, 1, 0x26 }, // DleteChar
53 { SDLK_QUOTE, 0, 0x27 }, // ' (single-quote)
54 // { SDLK_, 1, 0x28 }, // SLCT/MARK
55 // { SDLK_, 1, 0x29 }, // INPUT/MODE
56 // { SDLK_, 1, 0x2a }, // HELP
57 // Keycode 2B not used
58 { SDLK_COMMA, 0, 0x2c }, // , [Comma]
59 { SDLK_MINUS, 0, 0x2d }, // - [Dash]
60 { SDLK_PERIOD, 0, 0x2e }, // . [Period]
61 { SDLK_SLASH, 0, 0x2f }, // / [Forward-slash]
62 { SDLK_0, 0, 0x30 }, // 0
63 { SDLK_1, 0, 0x31 }, // 1
64 { SDLK_2, 0, 0x32 }, // 2
65 { SDLK_3, 0, 0x33 }, // 3
66 { SDLK_4, 0, 0x34 }, // 4
67 { SDLK_5, 0, 0x35 }, // 5
68 { SDLK_6, 0, 0x36 }, // 6
69 { SDLK_7, 0, 0x37 }, // 7
70 { SDLK_8, 0, 0x38 }, // 8
71 { SDLK_9, 0, 0x39 }, // 9
72 // Keycode 3A not used
73 { SDLK_SEMICOLON, 0, 0x3b }, // ; [Semicolon]
74 // Keycode 3C not used
75 { SDLK_EQUALS, 0, 0x3d }, // = [Equals]
76 // Keycodes 3E, 3F, 40 not used
77 // { SDLK_, 1, 0x41 }, // CMD
78 // { SDLK_, 1, 0x42 }, // CLOSE/OPEN
79 { SDLK_KP7, 0, 0x43 }, // PRINT
80 { SDLK_KP8, 0, 0x44 }, // CLEAR/RFRSH
81 { SDLK_CAPSLOCK, 0, 0x45 }, // Caps Lock
82 { SDLK_KP9, 0, 0x46 }, // PAGE
83 { SDLK_KP4, 0, 0x47 }, // BEG
84 { SDLK_LSHIFT, 0, 0x48 }, // Left Shift
85 { SDLK_RSHIFT, 0, 0x49 }, // Right Shift
86 { SDLK_HOME, 0, 0x4a }, // Home
87 { SDLK_KP5, 0, 0x4a }, // Home [Keypad 5]
88 { SDLK_END, 0, 0x4b }, // End
89 { SDLK_KP6, 0, 0x4b }, // End [Keypad 6]
90 { SDLK_LCTRL, 0, 0x4c }, // Left Ctrl? \___ not sure which is left and which is right...
91 { SDLK_RCTRL, 0, 0x4d }, // Right Ctrl? /
92 // Keycodes 4E thru 5A not used
93 { SDLK_LEFTBRACKET, 0, 0x5b }, // [
94 { SDLK_BACKSLASH, 0, 0x5c }, // \ (backslash)
95 { SDLK_RIGHTBRACKET, 0, 0x5d }, // ]
96 // Keycodes 5E, 5F not used
97 { SDLK_BACKQUOTE, 0, 0x60 }, // `
98 { SDLK_a, 0, 0x61 }, // A
99 { SDLK_b, 0, 0x62 }, // B
100 { SDLK_c, 0, 0x63 }, // C
101 { SDLK_d, 0, 0x64 }, // D
102 { SDLK_e, 0, 0x65 }, // E
103 { SDLK_f, 0, 0x66 }, // F
104 { SDLK_g, 0, 0x67 }, // G
105 { SDLK_h, 0, 0x68 }, // H
106 { SDLK_i, 0, 0x69 }, // I
107 { SDLK_j, 0, 0x6a }, // J
108 { SDLK_k, 0, 0x6b }, // K
109 { SDLK_l, 0, 0x6c }, // L
110 { SDLK_m, 0, 0x6d }, // M
111 { SDLK_n, 0, 0x6e }, // N
112 { SDLK_o, 0, 0x6f }, // O
113 { SDLK_p, 0, 0x70 }, // P
114 { SDLK_q, 0, 0x71 }, // Q
115 { SDLK_r, 0, 0x72 }, // R
116 { SDLK_s, 0, 0x73 }, // S
117 { SDLK_t, 0, 0x74 }, // T
118 { SDLK_u, 0, 0x75 }, // U
119 { SDLK_v, 0, 0x76 }, // V
120 { SDLK_w, 0, 0x77 }, // W
121 { SDLK_x, 0, 0x78 }, // X
122 { SDLK_y, 0, 0x79 }, // Y
123 { SDLK_z, 0, 0x7a }, // Z
124 // Keycodes 7B, 7C, 7D not used
125 { SDLK_NUMLOCK, 0, 0x7e } // Numlock
126 // { SDLK_, 1, 0x7f }, // Dlete
127 };
129 /**
130 * List of key states
131 */
132 int keystate[0x80];
134 void keyboard_init(void)
135 {
136 // Set all key states to "not pressed"
137 for (int i=0; i<(sizeof(keystate)/sizeof(keystate[0])); i++) {
138 keystate[i] = 0;
139 }
140 }
142 void keyboard_event(SDL_Event *ev)
143 {
144 }