src/keyboard.c

changeset 74
51cbc7a44cd9
child 80
9581358e92b0
child 86
ebce87d87808
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/keyboard.c	Wed Dec 29 01:38:54 2010 +0000
     1.3 @@ -0,0 +1,144 @@
     1.4 +#include "SDL.h"
     1.5 +
     1.6 +/**
     1.7 + * Key map -- a mapping from SDLK_xxx constants to scancodes and vice versa.
     1.8 + */
     1.9 +struct {
    1.10 +	SDLKey			key;			///< SDLK_xxx key code constant
    1.11 +	int				extended;		///< 1 if this is an extended keycode
    1.12 +	unsigned char	scancode;		///< Keyboard scan code
    1.13 +} keymap[] = {
    1.14 +	{ SDLK_UP,				0,	0x01 },	// ROLL/Up		[UpArrow]
    1.15 +	{ SDLK_KP2,				0,	0x01 },	// ROLL/Up		[Keypad 2]
    1.16 +//	{ SDLK_,				1,	0x02 },	// Clear Line
    1.17 +//	{ SDLK_,				1,	0x03 },	// Rstrt / Ref
    1.18 +//	{ SDLK_,				1,	0x04 },	// Exit
    1.19 +	{ SDLK_KP1,				0,	0x05 },	// PREV			[Keypad 1]
    1.20 +//	{ SDLK_,				1,	0x06 },	// Msg
    1.21 +//	{ SDLK_,				1,	0x07 },	// Cancl
    1.22 +	{ SDLK_BACKSPACE,		0,	0x08 },	// Backspace
    1.23 +	{ SDLK_TAB,				0,	0x09 },	// Tab
    1.24 +//	{ SDLK_RETURN,			1,	0x0a },	// ENTER
    1.25 +	{ SDLK_DOWN,			0,	0x0b },	// ROLL/Down	[DownArrow]
    1.26 +	{ SDLK_KP0,				0,	0x0b },	// ROLL/Down	[Keypad 0]
    1.27 +	{ SDLK_KP3,				0,	0x0c },	// NEXT			[Keypad 3]
    1.28 +	{ SDLK_RETURN,			0,	0x0d },	// RETURN		[Return]
    1.29 +	{ SDLK_LEFT,			0,	0x0e },	// <--			[LeftArrow]
    1.30 +	{ SDLK_KP_MINUS,		0,	0x0e },	// <--			[Keypad -]
    1.31 +	{ SDLK_RIGHT,			0,	0x0f },	// -->			[RightArrow]
    1.32 +	{ SDLK_KP_PERIOD,		0,	0x0f },	// -->			[Keypad .]
    1.33 +//	{ SDLK_,				1,	0x10 },	// Creat
    1.34 +//	{ SDLK_,				1,	0x11 },	// Save
    1.35 +//	{ SDLK_,				1,	0x12 },	// Move
    1.36 +//	{ SDLK_,				1,	0x13 },	// Ops
    1.37 +//	{ SDLK_,				1,	0x14 },	// Copy
    1.38 +	{ SDLK_F1,				0,	0x15 },	// F1
    1.39 +	{ SDLK_F2,				0,	0x16 },	// F2
    1.40 +	{ SDLK_F3,				0,	0x17 },	// F3
    1.41 +	{ SDLK_F4,				0,	0x18 },	// F4
    1.42 +	{ SDLK_F5,				0,	0x19 },	// F5
    1.43 +	{ SDLK_F6,				0,	0x1a },	// F6
    1.44 +	{ SDLK_ESCAPE,			0,	0x1b },	// ESC/DEL		[Escape]
    1.45 +	{ SDLK_F7,				0,	0x1c },	// F7
    1.46 +	{ SDLK_F8,				0,	0x1d },	// F8
    1.47 +//	{ SDLK_,				1,	0x1e },	// Suspd
    1.48 +//	{ SDLK_,				1,	0x1f },	// Rsume
    1.49 +	{ SDLK_SPACE,			0,	0x20 },	// SPACE		[Spacebar]
    1.50 +//	{ SDLK_,				1,	0x21 },	// Undo
    1.51 +//	{ SDLK_,				1,	0x22 },	// Redo
    1.52 +//	{ SDLK_,				1,	0x23 },	// FIND
    1.53 +//	{ SDLK_,				1,	0x24 },	// RPLAC
    1.54 +	{ SDLK_BREAK,			0,	0x25 },	// RESET/BREAK	[Pause/Break]
    1.55 +//	{ SDLK_,				1,	0x26 },	// DleteChar
    1.56 +	{ SDLK_QUOTE,			0,	0x27 },	// ' (single-quote)
    1.57 +//	{ SDLK_,				1,	0x28 },	// SLCT/MARK
    1.58 +//	{ SDLK_,				1,	0x29 },	// INPUT/MODE
    1.59 +//	{ SDLK_,				1,	0x2a },	// HELP
    1.60 +//	Keycode 2B not used
    1.61 +	{ SDLK_COMMA,			0,	0x2c },	// ,			[Comma]
    1.62 +	{ SDLK_MINUS,			0,	0x2d },	// -			[Dash]
    1.63 +	{ SDLK_PERIOD,			0,	0x2e },	// .			[Period]
    1.64 +	{ SDLK_SLASH,			0,	0x2f },	// /			[Forward-slash]
    1.65 +	{ SDLK_0,				0,	0x30 },	// 0
    1.66 +	{ SDLK_1,				0,	0x31 },	// 1
    1.67 +	{ SDLK_2,				0,	0x32 },	// 2
    1.68 +	{ SDLK_3,				0,	0x33 },	// 3
    1.69 +	{ SDLK_4,				0,	0x34 },	// 4
    1.70 +	{ SDLK_5,				0,	0x35 },	// 5
    1.71 +	{ SDLK_6,				0,	0x36 },	// 6
    1.72 +	{ SDLK_7,				0,	0x37 },	// 7
    1.73 +	{ SDLK_8,				0,	0x38 },	// 8
    1.74 +	{ SDLK_9,				0,	0x39 },	// 9
    1.75 +// Keycode 3A not used
    1.76 +	{ SDLK_SEMICOLON,		0,	0x3b },	// ;			[Semicolon]
    1.77 +// Keycode 3C not used
    1.78 +	{ SDLK_EQUALS,			0,	0x3d },	// =			[Equals]
    1.79 +// Keycodes 3E, 3F, 40 not used
    1.80 +//	{ SDLK_,				1,	0x41 },	// CMD
    1.81 +//	{ SDLK_,				1,	0x42 },	// CLOSE/OPEN
    1.82 +	{ SDLK_KP7,				0,	0x43 },	// PRINT
    1.83 +	{ SDLK_KP8,				0,	0x44 },	// CLEAR/RFRSH
    1.84 +	{ SDLK_CAPSLOCK,		0,	0x45 },	// Caps Lock
    1.85 +	{ SDLK_KP9,				0,	0x46 },	// PAGE
    1.86 +	{ SDLK_KP4,				0,	0x47 },	// BEG
    1.87 +	{ SDLK_LSHIFT,			0,	0x48 },	// Left Shift
    1.88 +	{ SDLK_RSHIFT,			0,	0x49 },	// Right Shift
    1.89 +	{ SDLK_HOME,			0,	0x4a },	// Home
    1.90 +	{ SDLK_KP5,				0,	0x4a },	// Home			[Keypad 5]
    1.91 +	{ SDLK_END,				0,	0x4b },	// End
    1.92 +	{ SDLK_KP6,				0,	0x4b },	// End			[Keypad 6]
    1.93 +	{ SDLK_LCTRL,			0,	0x4c },	// Left Ctrl?	\___ not sure which is left and which is right...
    1.94 +	{ SDLK_RCTRL,			0,	0x4d },	// Right Ctrl?	/
    1.95 +// Keycodes 4E thru 5A not used
    1.96 +	{ SDLK_LEFTBRACKET,		0,	0x5b },	// [
    1.97 +	{ SDLK_BACKSLASH,		0,	0x5c },	// \ (backslash)
    1.98 +	{ SDLK_RIGHTBRACKET,	0,	0x5d },	// ]
    1.99 +// Keycodes 5E, 5F not used
   1.100 +	{ SDLK_BACKQUOTE,		0,	0x60 },	// `
   1.101 +	{ SDLK_a,				0,	0x61 },	// A
   1.102 +	{ SDLK_b,				0,	0x62 },	// B
   1.103 +	{ SDLK_c,				0,	0x63 },	// C
   1.104 +	{ SDLK_d,				0,	0x64 },	// D
   1.105 +	{ SDLK_e,				0,	0x65 },	// E
   1.106 +	{ SDLK_f,				0,	0x66 },	// F
   1.107 +	{ SDLK_g,				0,	0x67 },	// G
   1.108 +	{ SDLK_h,				0,	0x68 },	// H
   1.109 +	{ SDLK_i,				0,	0x69 },	// I
   1.110 +	{ SDLK_j,				0,	0x6a },	// J
   1.111 +	{ SDLK_k,				0,	0x6b },	// K
   1.112 +	{ SDLK_l,				0,	0x6c },	// L
   1.113 +	{ SDLK_m,				0,	0x6d },	// M
   1.114 +	{ SDLK_n,				0,	0x6e },	// N
   1.115 +	{ SDLK_o,				0,	0x6f },	// O
   1.116 +	{ SDLK_p,				0,	0x70 },	// P
   1.117 +	{ SDLK_q,				0,	0x71 },	// Q
   1.118 +	{ SDLK_r,				0,	0x72 },	// R
   1.119 +	{ SDLK_s,				0,	0x73 },	// S
   1.120 +	{ SDLK_t,				0,	0x74 },	// T
   1.121 +	{ SDLK_u,				0,	0x75 },	// U
   1.122 +	{ SDLK_v,				0,	0x76 },	// V
   1.123 +	{ SDLK_w,				0,	0x77 },	// W
   1.124 +	{ SDLK_x,				0,	0x78 },	// X
   1.125 +	{ SDLK_y,				0,	0x79 },	// Y
   1.126 +	{ SDLK_z,				0,	0x7a },	// Z
   1.127 +// Keycodes 7B, 7C, 7D not used
   1.128 +	{ SDLK_NUMLOCK,			0,	0x7e }		// Numlock
   1.129 +//	{ SDLK_,				1,	0x7f },	// Dlete
   1.130 +};
   1.131 +
   1.132 +/**
   1.133 + * List of key states
   1.134 + */
   1.135 +int keystate[0x80];
   1.136 +
   1.137 +void keyboard_init(void)
   1.138 +{
   1.139 +	// Set all key states to "not pressed"
   1.140 +	for (int i=0; i<(sizeof(keystate)/sizeof(keystate[0])); i++) {
   1.141 +		keystate[i] = 0;
   1.142 +	}
   1.143 +}
   1.144 +
   1.145 +void keyboard_event(SDL_Event *ev)
   1.146 +{
   1.147 +}