#include #include "../Keyboard.h" Keyboard keyboard; // TODO map unknown key codes uint8_t mapSdlKeycode(SDL_Keycode keyCode) { switch (keyCode) { case SDLK_UNKNOWN: return KeyUnknown; case SDLK_RETURN: return KeyUnknown; case SDLK_ESCAPE: return KeyEscape; case SDLK_BACKSPACE: return KeyBackspace; case SDLK_TAB: return KeyTab; case SDLK_SPACE: return KeySpace; case SDLK_EXCLAIM: return KeyUnknown; case SDLK_QUOTEDBL: return KeyUnknown; case SDLK_HASH: return KeyUnknown; case SDLK_PERCENT: return KeyUnknown; case SDLK_DOLLAR: return KeyUnknown; case SDLK_AMPERSAND: return KeyUnknown; case SDLK_QUOTE: return KeyUnknown; case SDLK_LEFTPAREN: return KeyUnknown; case SDLK_RIGHTPAREN: return KeyUnknown; case SDLK_ASTERISK: return KeyUnknown; case SDLK_PLUS: return KeyUnknown; case SDLK_COMMA: return KeyUnknown; case SDLK_MINUS: return KeyUnknown; case SDLK_PERIOD: return KeyUnknown; case SDLK_SLASH: return KeyUnknown; case SDLK_0: return KeyUnknown; case SDLK_1: return KeyUnknown; case SDLK_2: return KeyUnknown; case SDLK_3: return KeyUnknown; case SDLK_4: return KeyUnknown; case SDLK_5: return KeyUnknown; case SDLK_6: return KeyUnknown; case SDLK_7: return KeyUnknown; case SDLK_8: return KeyUnknown; case SDLK_9: return KeyUnknown; case SDLK_COLON: return KeyUnknown; case SDLK_SEMICOLON: return KeyUnknown; case SDLK_LESS: return KeyUnknown; case SDLK_EQUALS: return KeyUnknown; case SDLK_GREATER: return KeyUnknown; case SDLK_QUESTION: return KeyUnknown; case SDLK_AT: return KeyUnknown; case SDLK_LEFTBRACKET: return KeyUnknown; case SDLK_BACKSLASH: return KeyUnknown; case SDLK_RIGHTBRACKET: return KeyUnknown; case SDLK_CARET: return KeyUnknown; case SDLK_UNDERSCORE: return KeyUnknown; case SDLK_BACKQUOTE: return KeyUnknown; case SDLK_a: return KeyUnknown; case SDLK_b: return KeyUnknown; case SDLK_c: return KeyUnknown; case SDLK_d: return KeyUnknown; case SDLK_e: return KeyUnknown; case SDLK_f: return KeyUnknown; case SDLK_g: return KeyUnknown; case SDLK_h: return KeyUnknown; case SDLK_i: return KeyUnknown; case SDLK_j: return KeyUnknown; case SDLK_k: return KeyUnknown; case SDLK_l: return KeyUnknown; case SDLK_m: return KeyUnknown; case SDLK_n: return KeyUnknown; case SDLK_o: return KeyO; case SDLK_p: return KeyP; case SDLK_q: return KeyQ; case SDLK_r: return KeyR; case SDLK_s: return KeyS; case SDLK_t: return KeyT; case SDLK_u: return KeyU; case SDLK_v: return KeyV; case SDLK_w: return KeyW; case SDLK_x: return KeyX; case SDLK_y: return KeyY; case SDLK_z: return KeyZ; case SDLK_CAPSLOCK: return KeyCapsLock; case SDLK_F1: return KeyF1; case SDLK_F2: return KeyF2; case SDLK_F3: return KeyF3; case SDLK_F4: return KeyF4; case SDLK_F5: return KeyF5; case SDLK_F6: return KeyF6; case SDLK_F7: return KeyF7; case SDLK_F8: return KeyF8; case SDLK_F9: return KeyF9; case SDLK_F10: return KeyF10; case SDLK_F11: return KeyF11; case SDLK_F12: return KeyF12; case SDLK_PRINTSCREEN: return KeyPrint; case SDLK_SCROLLLOCK: return KeyScrollLock; case SDLK_PAUSE: return KeyPause; case SDLK_INSERT: return KeyInsert; case SDLK_HOME: return KeyHome; case SDLK_PAGEUP: return KeyPageUp; case SDLK_DELETE: return KeyDelete; case SDLK_END: return KeyEnd; case SDLK_PAGEDOWN: return KeyPageDown; case SDLK_RIGHT: return KeyRight; case SDLK_LEFT: return KeyLeft; case SDLK_DOWN: return KeyDown; case SDLK_UP: return KeyUp; case SDLK_NUMLOCKCLEAR: return KeyUnknown; case SDLK_KP_DIVIDE: return KeyUnknown; case SDLK_KP_MULTIPLY: return KeyUnknown; case SDLK_KP_MINUS: return KeyUnknown; case SDLK_KP_PLUS: return KeyUnknown; case SDLK_KP_ENTER: return KeyUnknown; case SDLK_KP_1: return KeyUnknown; case SDLK_KP_2: return KeyUnknown; case SDLK_KP_3: return KeyUnknown; case SDLK_KP_4: return KeyUnknown; case SDLK_KP_5: return KeyUnknown; case SDLK_KP_6: return KeyUnknown; case SDLK_KP_7: return KeyUnknown; case SDLK_KP_8: return KeyUnknown; case SDLK_KP_9: return KeyUnknown; case SDLK_KP_0: return KeyUnknown; case SDLK_KP_PERIOD: return KeyUnknown; case SDLK_APPLICATION: return KeyUnknown; case SDLK_POWER: return KeyUnknown; case SDLK_KP_EQUALS: return KeyUnknown; case SDLK_F13: return KeyUnknown; case SDLK_F14: return KeyUnknown; case SDLK_F15: return KeyUnknown; case SDLK_F16: return KeyUnknown; case SDLK_F17: return KeyUnknown; case SDLK_F18: return KeyUnknown; case SDLK_F19: return KeyUnknown; case SDLK_F20: return KeyUnknown; case SDLK_F21: return KeyUnknown; case SDLK_F22: return KeyUnknown; case SDLK_F23: return KeyUnknown; case SDLK_F24: return KeyUnknown; case SDLK_EXECUTE: return KeyUnknown; case SDLK_HELP: return KeyUnknown; case SDLK_MENU: return KeyUnknown; case SDLK_SELECT: return KeyUnknown; case SDLK_STOP: return KeyUnknown; case SDLK_AGAIN: return KeyUnknown; case SDLK_UNDO: return KeyUnknown; case SDLK_CUT: return KeyUnknown; case SDLK_COPY: return KeyUnknown; case SDLK_PASTE: return KeyUnknown; case SDLK_FIND: return KeyUnknown; case SDLK_MUTE: return KeyUnknown; case SDLK_VOLUMEUP: return KeyUnknown; case SDLK_VOLUMEDOWN: return KeyUnknown; case SDLK_KP_COMMA: return KeyUnknown; case SDLK_KP_EQUALSAS400: return KeyUnknown; case SDLK_ALTERASE: return KeyUnknown; case SDLK_SYSREQ: return KeyUnknown; case SDLK_CANCEL: return KeyUnknown; case SDLK_CLEAR: return KeyUnknown; case SDLK_PRIOR: return KeyUnknown; case SDLK_RETURN2: return KeyUnknown; case SDLK_SEPARATOR: return KeyUnknown; case SDLK_OUT: return KeyUnknown; case SDLK_OPER: return KeyUnknown; case SDLK_CLEARAGAIN: return KeyUnknown; case SDLK_CRSEL: return KeyUnknown; case SDLK_EXSEL: return KeyUnknown; case SDLK_KP_00: return KeyUnknown; case SDLK_KP_000: return KeyUnknown; case SDLK_THOUSANDSSEPARATOR: return KeyUnknown; case SDLK_DECIMALSEPARATOR: return KeyUnknown; case SDLK_CURRENCYUNIT: return KeyUnknown; case SDLK_CURRENCYSUBUNIT: return KeyUnknown; case SDLK_KP_LEFTPAREN: return KeyUnknown; case SDLK_KP_RIGHTPAREN: return KeyUnknown; case SDLK_KP_LEFTBRACE: return KeyUnknown; case SDLK_KP_RIGHTBRACE: return KeyUnknown; case SDLK_KP_TAB: return KeyUnknown; case SDLK_KP_BACKSPACE: return KeyUnknown; case SDLK_KP_A: return KeyUnknown; case SDLK_KP_B: return KeyUnknown; case SDLK_KP_C: return KeyUnknown; case SDLK_KP_D: return KeyUnknown; case SDLK_KP_E: return KeyUnknown; case SDLK_KP_F: return KeyUnknown; case SDLK_KP_XOR: return KeyUnknown; case SDLK_KP_POWER: return KeyUnknown; case SDLK_KP_PERCENT: return KeyUnknown; case SDLK_KP_LESS: return KeyUnknown; case SDLK_KP_GREATER: return KeyUnknown; case SDLK_KP_AMPERSAND: return KeyUnknown; case SDLK_KP_DBLAMPERSAND: return KeyUnknown; case SDLK_KP_VERTICALBAR: return KeyUnknown; case SDLK_KP_DBLVERTICALBAR: return KeyUnknown; case SDLK_KP_COLON: return KeyUnknown; case SDLK_KP_HASH: return KeyUnknown; case SDLK_KP_SPACE: return KeyUnknown; case SDLK_KP_AT: return KeyUnknown; case SDLK_KP_EXCLAM: return KeyUnknown; case SDLK_KP_MEMSTORE: return KeyUnknown; case SDLK_KP_MEMRECALL: return KeyUnknown; case SDLK_KP_MEMCLEAR: return KeyUnknown; case SDLK_KP_MEMADD: return KeyUnknown; case SDLK_KP_MEMSUBTRACT: return KeyUnknown; case SDLK_KP_MEMMULTIPLY: return KeyUnknown; case SDLK_KP_MEMDIVIDE: return KeyUnknown; case SDLK_KP_PLUSMINUS: return KeyUnknown; case SDLK_KP_CLEAR: return KeyUnknown; case SDLK_KP_CLEARENTRY: return KeyUnknown; case SDLK_KP_BINARY: return KeyUnknown; case SDLK_KP_OCTAL: return KeyUnknown; case SDLK_KP_DECIMAL: return KeyUnknown; case SDLK_KP_HEXADECIMAL: return KeyUnknown; case SDLK_LCTRL: return KeyLeftCtrl; case SDLK_LSHIFT: return KeyLeftShift; case SDLK_LALT: return KeyLeftAlt; case SDLK_LGUI: return KeyUnknown; case SDLK_RCTRL: return KeyRightControl; case SDLK_RSHIFT: return KeyRightShift; case SDLK_RALT: return KeyRightAlt; case SDLK_RGUI: return KeyUnknown; case SDLK_MODE: return KeyUnknown; case SDLK_AUDIONEXT: return KeyUnknown; case SDLK_AUDIOPREV: return KeyUnknown; case SDLK_AUDIOSTOP: return KeyUnknown; case SDLK_AUDIOPLAY: return KeyUnknown; case SDLK_AUDIOMUTE: return KeyUnknown; case SDLK_MEDIASELECT: return KeyUnknown; case SDLK_WWW: return KeyUnknown; case SDLK_MAIL: return KeyUnknown; case SDLK_CALCULATOR: return KeyUnknown; case SDLK_COMPUTER: return KeyUnknown; case SDLK_AC_SEARCH: return KeyUnknown; case SDLK_AC_HOME: return KeyUnknown; case SDLK_AC_BACK: return KeyUnknown; case SDLK_AC_FORWARD: return KeyUnknown; case SDLK_AC_STOP: return KeyUnknown; case SDLK_AC_REFRESH: return KeyUnknown; case SDLK_AC_BOOKMARKS: return KeyUnknown; case SDLK_BRIGHTNESSDOWN: return KeyUnknown; case SDLK_BRIGHTNESSUP: return KeyUnknown; case SDLK_DISPLAYSWITCH: return KeyUnknown; case SDLK_KBDILLUMTOGGLE: return KeyUnknown; case SDLK_KBDILLUMDOWN: return KeyUnknown; case SDLK_KBDILLUMUP: return KeyUnknown; case SDLK_EJECT: return KeyUnknown; case SDLK_SLEEP: return KeyUnknown; case SDLK_APP1: return KeyUnknown; case SDLK_APP2: return KeyUnknown; case SDLK_AUDIOREWIND: return KeyUnknown; case SDLK_AUDIOFASTFORWARD: return KeyUnknown; case SDLK_SOFTLEFT: return KeyUnknown; case SDLK_SOFTRIGHT: return KeyUnknown; case SDLK_CALL: return KeyUnknown; case SDLK_ENDCALL: return KeyUnknown; default: ; } return KeyUnknown; } static const char *keyNames[] = { "", "KeyEscape", // = 0x01, "Key1", // = 0x02, "Key2", // = 0x03, "Key3", // = 0x04, "Key4", // = 0x05, "Key5", // = 0x06, "Key6", // = 0x07, "Key7", // = 0x08, "Key8", // = 0x09, "Key9", // = 0x0a, "Key0", // = 0x0b, "KeyMinus", // = 0x0c, "KeyEqual", // = 0x0d, "KeyBackspace", // = 0x0e, "KeyTab", // = 0x0f, "KeyQ", // = 0x10, "KeyW", // = 0x11, "KeyE", // = 0x12, "KeyR", // = 0x13, "KeyT", // = 0x14, "KeyY", // = 0x15, "KeyU", // = 0x16, "KeyI", // = 0x17, "KeyO", // = 0x18, "KeyP", // = 0x19, "KeyBracketLeft", // = 0x1a, "KeyBracketRight", // = 0x1b, "KeyEnter", // = 0x1c, "KeyLeftCtrl", // = 0x1d, "KeyA", // = 0x1e, "KeyS", // = 0x1f, "KeyD", // = 0x20, "KeyF", // = 0x21, "KeyG", // = 0x22, "KeyH", // = 0x23, "KeyJ", // = 0x24, "KeyK", // = 0x25, "KeyL", // = 0x26, "KeySemicolon", // = 0x27, "KeyApostrophe", // = 0x28, "KeyBacktick", // = 0x29, "KeyLeftShift", // = 0x2a, "KeyBackslash", // = 0x2b, "KeyZ", // = 0x2c, "KeyX", // = 0x2d, "KeyC", // = 0x2e, "KeyV", // = 0x2f, "KeyB", // = 0x30, "KeyN", // = 0x31, "KeyM", // = 0x32, "KeyComma", // = 0x33, "KeyPeriod", // = 0x34, "KeySlash", // = 0x35, "KeyRightShift", // = 0x36, "KeyKeypadMultiply", // = 0x37, "KeyLeftAlt", // = 0x38, "KeySpace", // = 0x39, "KeyCapsLock", // = 0x3a, "KeyF1", // = 0x3b, "KeyF2", // = 0x3c, "KeyF3", // = 0x3d, "KeyF4", // = 0x3e, "KeyF5", // = 0x3f, "KeyF6", // = 0x40, "KeyF7", // = 0x41, "KeyF8", // = 0x42, "KeyF9", // = 0x43, "KeyF10", // = 0x44, "KeyNumLock", // = 0x45, "KeyScrollLock", // = 0x46, "KeyKeypad7", // = 0x47, "KeyKeypad8", // = 0x48, "KeyKeypad9", // = 0x49, "KeyKeypadMinus", // = 0x4a, "KeyKeypad4", // = 0x4b, "KeyKeypad5", // = 0x4c, "KeyKeypad6", // = 0x4d, "KeyKeypadPlus", // = 0x4e, "KeyKeypad1", // = 0x4f, "KeyKeypad2", // = 0x50, "KeyKeypad3", // = 0x51, "KeyKeypad0", // = 0x52, "KeyKeypadPeriod", // = 0x53, "", "", "", "KeyF11", // = 0x57, "KeyF12", // = 0x58, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "KeyMediaPrev", // = 0x90, "", "", "", "", "", "", "", "", "KeyMediaNext", // = 0x99, "", "", "KeyKeypadEnter", // = 0x9c, "KeyRightControl", // = 0x9d, "", "", "KeyMediaMute", // = 0xa0, "KeyMediaCalculator", // = 0xa1, "KeyMediaPlay", // = 0xa2, "", "KeyMediaStop", // = 0xa4, "", "", "", "", "", "", "", "", "", "KeyMediaVolumeDown", // = 0xae, "", "KeyMediaVolumeUp", // = 0xb0, "", "KeyMediaWww", // = 0xb2, "", "", "KeyKeypadDivide", // = 0xb5, "", "", "KeyRightAlt", // = 0xb8, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "KeyHome", // = 0xc7, "KeyUp", // = 0xc8, "KeyPageUp", // = 0xc9, "", "KeyLeft", // = 0xcb, "", "KeyRight", // = 0xcd, "", "KeyEnd", // = 0xcf, "KeyDown", // = 0xd0, "KeyPageDown", // = 0xd1, "KeyInsert", // = 0xd2, "KeyDelete", // = 0xd3, "", "", "", "", "", "", "", "KeyLeftGui", // = 0xdb, "KeyRightGui", // = 0xdc, "KeyApps", // = 0xdd, "KeyAcpiPower", // = 0xde, "KeyAcpiSleep", // = 0xdf, "", "", "", "KeyAcpiWake", // = 0xe3, "", "KeyMediaWwwSearch", // = 0xe5, "KeyMediaWwwFavorites", // = 0xe6, "KeyMediaWwwRefresh", // = 0xe7, "KeyMediaWwwStop", // = 0xe8, "KeyMediaWwwForward", // = 0xe9, "KeyMediaWwwBack", // = 0xea, "KeyMediaMyComputer", // = 0xeb, "KeyMediaEmail", // = 0xec, "KeyMediaSelect", // = 0xed, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "KeyPrint", // = 0xfe, "KeyPause", // = 0xff, }; void keyboardIsr() { keyboard.Isr(); } Keyboard::Keyboard() { // TODO } Keyboard::~Keyboard() { // TODO } Keyboard::KeyHandleFunction Keyboard::setKeyUpHandler(KeyHandleFunction handler) { auto oldHandler = _keyUpHandler; _keyUpHandler = handler; return oldHandler; } Keyboard::KeyHandleFunction Keyboard::setKeyDownHandler(KeyHandleFunction handler) { auto oldHandler = _keyDownHandler; _keyDownHandler = handler; return oldHandler; } Keyboard::KeyHandleFunction Keyboard::setKeyRepeatHandler(KeyHandleFunction handler) { auto oldHandler = _keyRepeatHandler; _keyRepeatHandler = handler; return oldHandler; } const char *Keyboard::getKeyName(unsigned char keyCode) { return keyNames[keyCode]; } void Keyboard::Isr() { // TODO } void Keyboard::keyDown(SDL_Keycode keyCode) { auto c = mapSdlKeycode(keyCode); if (keyState[c]) { if (_keyRepeatHandler) _keyRepeatHandler(c); } else { keyState[c] = true; if (_keyDownHandler) _keyDownHandler(c); } } void Keyboard::keyUp(SDL_Keycode keyCode) { auto c = mapSdlKeycode(keyCode); keyState[c] = false; if (_keyUpHandler) _keyUpHandler(c); }