enum {
    kVK_ANSI_A                    = 0x00,
    kVK_ANSI_S                    = 0x01,
    kVK_ANSI_D                    = 0x02,
    kVK_ANSI_F                    = 0x03,
    kVK_ANSI_H                    = 0x04,
    kVK_ANSI_G                    = 0x05,
    kVK_ANSI_Z                    = 0x06,
    kVK_ANSI_X                    = 0x07,
    kVK_ANSI_C                    = 0x08,
    kVK_ANSI_V                    = 0x09,
    kVK_ANSI_B                    = 0x0B,
    kVK_ANSI_Q                    = 0x0C,
    kVK_ANSI_W                    = 0x0D,
    kVK_ANSI_E                    = 0x0E,
    kVK_ANSI_R                    = 0x0F,
    kVK_ANSI_Y                    = 0x10,
    kVK_ANSI_T                    = 0x11,
    kVK_ANSI_1                    = 0x12,
    kVK_ANSI_2                    = 0x13,
    kVK_ANSI_3                    = 0x14,
    kVK_ANSI_4                    = 0x15,
    kVK_ANSI_6                    = 0x16,
    kVK_ANSI_5                    = 0x17,
    kVK_ANSI_Equal                = 0x18,
    kVK_ANSI_9                    = 0x19,
    kVK_ANSI_7                    = 0x1A,
    kVK_ANSI_Minus                = 0x1B,
    kVK_ANSI_8                    = 0x1C,
    kVK_ANSI_0                    = 0x1D,
    kVK_ANSI_RightBracket         = 0x1E,
    kVK_ANSI_O                    = 0x1F,
    kVK_ANSI_U                    = 0x20,
    kVK_ANSI_LeftBracket          = 0x21,
    kVK_ANSI_I                    = 0x22,
    kVK_ANSI_P                    = 0x23,
    kVK_ANSI_L                    = 0x25,
    kVK_ANSI_J                    = 0x26,
    kVK_ANSI_Quote                = 0x27,
    kVK_ANSI_K                    = 0x28,
    kVK_ANSI_Semicolon            = 0x29,
    kVK_ANSI_Backslash            = 0x2A,
    kVK_ANSI_Comma                = 0x2B,
    kVK_ANSI_Slash                = 0x2C,
    kVK_ANSI_N                    = 0x2D,
    kVK_ANSI_M                    = 0x2E,
    kVK_ANSI_Period               = 0x2F,
    kVK_ANSI_Grave                = 0x32,
    kVK_ANSI_KeypadDecimal        = 0x41,
    kVK_ANSI_KeypadMultiply       = 0x43,
    kVK_ANSI_KeypadPlus           = 0x45,
    kVK_ANSI_KeypadClear          = 0x47,
    kVK_ANSI_KeypadDivide         = 0x4B,
    kVK_ANSI_KeypadEnter          = 0x4C,
    kVK_ANSI_KeypadMinus          = 0x4E,
    kVK_ANSI_KeypadEquals         = 0x51,
    kVK_ANSI_Keypad0              = 0x52,
    kVK_ANSI_Keypad1              = 0x53,
    kVK_ANSI_Keypad2              = 0x54,
    kVK_ANSI_Keypad3              = 0x55,
    kVK_ANSI_Keypad4              = 0x56,
    kVK_ANSI_Keypad5              = 0x57,
    kVK_ANSI_Keypad6              = 0x58,
    kVK_ANSI_Keypad7              = 0x59,
    kVK_ANSI_Keypad8              = 0x5B,
    kVK_ANSI_Keypad9              = 0x5C
};

/* keycodes for keys that are independent of keyboard layout*/
enum {
    kVK_Return                    = 0x24,
    kVK_Tab                       = 0x30,
    kVK_Space                     = 0x31,
    kVK_Delete                    = 0x33,
    kVK_Escape                    = 0x35,
    kVK_Command                   = 0x37,
    kVK_Shift                     = 0x38,
    kVK_CapsLock                  = 0x39,
    kVK_Option                    = 0x3A,
    kVK_Control                   = 0x3B,
    kVK_RightShift                = 0x3C,
    kVK_RightOption               = 0x3D,
    kVK_RightControl              = 0x3E,
    kVK_Function                  = 0x3F,
    kVK_F17                       = 0x40,
    kVK_VolumeUp                  = 0x48,
    kVK_VolumeDown                = 0x49,
    kVK_Mute                      = 0x4A,
    kVK_F18                       = 0x4F,
    kVK_F19                       = 0x50,
    kVK_F20                       = 0x5A,
    kVK_F5                        = 0x60,
    kVK_F6                        = 0x61,
    kVK_F7                        = 0x62,
    kVK_F3                        = 0x63,
    kVK_F8                        = 0x64,
    kVK_F9                        = 0x65,
    kVK_F11                       = 0x67,
    kVK_F13                       = 0x69,
    kVK_F16                       = 0x6A,
    kVK_F14                       = 0x6B,
    kVK_F10                       = 0x6D,
    kVK_F12                       = 0x6F,
    kVK_F15                       = 0x71,
    kVK_Help                      = 0x72,
    kVK_Home                      = 0x73,
    kVK_PageUp                    = 0x74,
    kVK_ForwardDelete             = 0x75,
    kVK_F4                        = 0x76,
    kVK_End                       = 0x77,
    kVK_F2                        = 0x78,
    kVK_PageDown                  = 0x79,
    kVK_F1                        = 0x7A,
    kVK_LeftArrow                 = 0x7B,
    kVK_RightArrow                = 0x7C,
    kVK_DownArrow                 = 0x7D,
    kVK_UpArrow                   = 0x7E
};

kKey convert_key(int key)
{
#define CASE(K,V) case K: return V;
    switch(key)
    {
#ifdef __APPLE__
    CASE(kVK_ANSI_A, kKey::KeyA);
    CASE(kVK_ANSI_S, kKey::KeyS);
    CASE(kVK_ANSI_D, kKey::KeyD);
    CASE(kVK_ANSI_F, kKey::KeyF);
    CASE(kVK_ANSI_H, kKey::KeyH);
    CASE(kVK_ANSI_G, kKey::KeyG);
    CASE(kVK_ANSI_Z, kKey::KeyZ);
    CASE(kVK_ANSI_X, kKey::KeyX);
    CASE(kVK_ANSI_C, kKey::KeyC);
    CASE(kVK_ANSI_V, kKey::KeyV);
    CASE(kVK_ANSI_B, kKey::KeyB);
    CASE(kVK_ANSI_Q, kKey::KeyQ);
    CASE(kVK_ANSI_W, kKey::KeyW);
    CASE(kVK_ANSI_E, kKey::KeyE);
    CASE(kVK_ANSI_R, kKey::KeyR);
    CASE(kVK_ANSI_Y, kKey::KeyY);
    CASE(kVK_ANSI_T, kKey::KeyT);
    CASE(kVK_ANSI_1, kKey::Key1);
    CASE(kVK_ANSI_2, kKey::Key2);
    CASE(kVK_ANSI_3, kKey::Key3);
    CASE(kVK_ANSI_4, kKey::Key4);
    CASE(kVK_ANSI_6, kKey::Key6);
    CASE(kVK_ANSI_5, kKey::Key5);
    CASE(kVK_ANSI_Equal, kKey::Unknown);
    CASE(kVK_ANSI_9, kKey::Key9);
    CASE(kVK_ANSI_7, kKey::Key7);
    CASE(kVK_ANSI_Minus, kKey::Unknown);
    CASE(kVK_ANSI_8, kKey::Key8);
    CASE(kVK_ANSI_0, kKey::Key0);
    CASE(kVK_ANSI_RightBracket, kKey::Unknown);
    CASE(kVK_ANSI_O, kKey::KeyO);
    CASE(kVK_ANSI_U, kKey::KeyU);
    CASE(kVK_ANSI_LeftBracket, kKey::Unknown);
    CASE(kVK_ANSI_I, kKey::KeyI);
    CASE(kVK_ANSI_P, kKey::KeyP);
    CASE(kVK_ANSI_L, kKey::KeyL);
    CASE(kVK_ANSI_J, kKey::KeyJ);
    CASE(kVK_ANSI_Quote, kKey::Unknown);
    CASE(kVK_ANSI_K, kKey::KeyK);
    CASE(kVK_ANSI_Semicolon, kKey::Unknown);
    CASE(kVK_ANSI_Backslash, kKey::Unknown);
    CASE(kVK_ANSI_Comma, kKey::Unknown);
    CASE(kVK_ANSI_Slash, kKey::Unknown);
    CASE(kVK_ANSI_N, kKey::KeyN);
    CASE(kVK_ANSI_M, kKey::KeyM);
    CASE(kVK_ANSI_Period, kKey::Unknown);
    CASE(kVK_ANSI_Grave, kKey::Unknown);
    CASE(kVK_ANSI_KeypadDecimal, kKey::Unknown);
    CASE(kVK_ANSI_KeypadMultiply, kKey::Unknown);
    CASE(kVK_ANSI_KeypadPlus, kKey::Unknown);
    CASE(kVK_ANSI_KeypadClear, kKey::Unknown);
    CASE(kVK_ANSI_KeypadDivide, kKey::Unknown);
    CASE(kVK_ANSI_KeypadEnter, kKey::Unknown);
    CASE(kVK_ANSI_KeypadMinus, kKey::Unknown);
    CASE(kVK_ANSI_KeypadEquals, kKey::Unknown);
    CASE(kVK_ANSI_Keypad0, kKey::Unknown);
    CASE(kVK_ANSI_Keypad1, kKey::Unknown);
    CASE(kVK_ANSI_Keypad2, kKey::Unknown);
    CASE(kVK_ANSI_Keypad3, kKey::Unknown);
    CASE(kVK_ANSI_Keypad4, kKey::Unknown);
    CASE(kVK_ANSI_Keypad5, kKey::Unknown);
    CASE(kVK_ANSI_Keypad6, kKey::Unknown);
    CASE(kVK_ANSI_Keypad7, kKey::Unknown);
    CASE(kVK_ANSI_Keypad8, kKey::Unknown);
    CASE(kVK_ANSI_Keypad9, kKey::Unknown);
    CASE(kVK_Return, kKey::KeyEnter);
    CASE(kVK_Tab, kKey::KeyTab);
    CASE(kVK_Space, kKey::Unknown);
    CASE(kVK_Delete, kKey::Unknown);
    CASE(kVK_Escape, kKey::Unknown);
    CASE(kVK_Command, kKey::KeyCtrl);
    CASE(kVK_Shift, kKey::KeyShift);
    CASE(kVK_CapsLock, kKey::Unknown);
    CASE(kVK_Option, kKey::Unknown);
    CASE(kVK_Control, kKey::Unknown);
    CASE(kVK_RightShift, kKey::Unknown);
    CASE(kVK_RightOption, kKey::Unknown);
    CASE(kVK_RightControl, kKey::Unknown);
    CASE(kVK_Function, kKey::Unknown);
    CASE(kVK_F17, kKey::Unknown);
    CASE(kVK_VolumeUp, kKey::Unknown);
    CASE(kVK_VolumeDown, kKey::Unknown);
    CASE(kVK_Mute, kKey::Unknown);
    CASE(kVK_F18, kKey::KeyF18);
    CASE(kVK_F19, kKey::KeyF19);
    CASE(kVK_F20, kKey::KeyF20);
    CASE(kVK_F5, kKey::KeyF5);
    CASE(kVK_F6, kKey::KeyF6);
    CASE(kVK_F7, kKey::KeyF7);
    CASE(kVK_F3, kKey::KeyF3);
    CASE(kVK_F8, kKey::KeyF8);
    CASE(kVK_F9, kKey::KeyF9);
    CASE(kVK_F11, kKey::KeyF11);
    CASE(kVK_F13, kKey::KeyF13);
    CASE(kVK_F16, kKey::KeyF16);
    CASE(kVK_F14, kKey::KeyF14);
    CASE(kVK_F10, kKey::KeyF10);
    CASE(kVK_F12, kKey::KeyF12);
    CASE(kVK_F15, kKey::KeyF15);
    CASE(kVK_Help, kKey::Unknown);
    CASE(kVK_Home, kKey::Unknown);
    CASE(kVK_PageUp, kKey::Unknown);
    CASE(kVK_ForwardDelete, kKey::Unknown);
    CASE(kVK_F4, kKey::Unknown);
    CASE(kVK_End, kKey::Unknown);
    CASE(kVK_F2, kKey::Unknown);
    CASE(kVK_PageDown, kKey::Unknown);
    CASE(kVK_F1, kKey::Unknown);
    CASE(kVK_LeftArrow, kKey::Unknown);
    CASE(kVK_RightArrow, kKey::Unknown);
    CASE(kVK_DownArrow, kKey::Unknown);
    CASE(kVK_UpArrow, kKey::Unknown);
#elif defined(_WIN32)
    CASE(VK_LBUTTON, kKey::Unknown);
    CASE(VK_RBUTTON, kKey::Unknown);
    CASE(VK_CANCEL, kKey::Unknown);
    CASE(VK_MBUTTON, kKey::Unknown);
    CASE(VK_XBUTTON1, kKey::Unknown);
    CASE(VK_XBUTTON2, kKey::Unknown);
    CASE(VK_BACK, kKey::Unknown);
    CASE(VK_TAB, kKey::KeyTab);
    CASE(VK_CLEAR, kKey::Unknown);
    CASE(VK_RETURN, kKey::Unknown);
    CASE(VK_SHIFT, kKey::KeyShift);
    CASE(VK_CONTROL, kKey::KeyCtrl);
    CASE(VK_MENU, kKey::KeyAlt);
    CASE(VK_PAUSE, kKey::Unknown);
    CASE(VK_CAPITAL, kKey::Unknown);
    CASE(VK_KANA, kKey::Unknown);
    //CASE(VK_HANGEUL, kKey::Unknown); // same as VK_KANA
    //CASE(VK_HANGUL, kKey::Unknown);  // same as VK_KANA
    CASE(VK_JUNJA, kKey::Unknown);
    CASE(VK_FINAL, kKey::Unknown);
    CASE(VK_HANJA, kKey::Unknown);
    //CASE(VK_KANJI, kKey::Unknown); // same as VK_HANJA
    CASE(VK_ESCAPE, kKey::Unknown);
    CASE(VK_CONVERT, kKey::Unknown);
    CASE(VK_NONCONVERT, kKey::Unknown);
    CASE(VK_ACCEPT, kKey::Unknown);
    CASE(VK_MODECHANGE, kKey::Unknown);
    CASE(VK_SPACE, kKey::KeySpacebar);
    CASE(VK_PRIOR, kKey::Unknown);
    CASE(VK_NEXT, kKey::Unknown);
    CASE(VK_END, kKey::Unknown);
    CASE(VK_HOME, kKey::Unknown);
    CASE(VK_LEFT, kKey::Unknown);
    CASE(VK_UP, kKey::Unknown);
    CASE(VK_RIGHT, kKey::Unknown);
    CASE(VK_DOWN, kKey::Unknown);
    CASE(VK_SELECT, kKey::Unknown);
    CASE(VK_PRINT, kKey::Unknown);
    CASE(VK_EXECUTE, kKey::Unknown);
    CASE(VK_SNAPSHOT, kKey::Unknown);
    CASE(VK_INSERT, kKey::Unknown);
    CASE(VK_DELETE, kKey::Unknown);
    CASE(VK_HELP, kKey::Unknown);
    CASE('0', kKey::Key0);
    CASE('1', kKey::Key1);
    CASE('2', kKey::Key2);
    CASE('3', kKey::Key3);
    CASE('4', kKey::Key4);
    CASE('5', kKey::Key5);
    CASE('6', kKey::Key6);
    CASE('7', kKey::Key7);
    CASE('8', kKey::Key8);
    CASE('9', kKey::Key9);
    CASE('A', kKey::KeyA);
    CASE('B', kKey::KeyB);
    CASE('C', kKey::KeyC);
    CASE('D', kKey::KeyD);
    CASE('E', kKey::KeyE);
    CASE('F', kKey::KeyF);
    CASE('G', kKey::KeyG);
    CASE('H', kKey::KeyH);
    CASE('I', kKey::KeyI);
    CASE('J', kKey::KeyJ);
    CASE('K', kKey::KeyK);
    CASE('L', kKey::KeyL);
    CASE('M', kKey::KeyM);
    CASE('N', kKey::KeyN);
    CASE('O', kKey::KeyO);
    CASE('P', kKey::KeyP);
    CASE('Q', kKey::KeyQ);
    CASE('R', kKey::KeyR);
    CASE('S', kKey::KeyS);
    CASE('T', kKey::KeyT);
    CASE('U', kKey::KeyU);
    CASE('V', kKey::KeyV);
    CASE('W', kKey::KeyW);
    CASE('X', kKey::KeyX);
    CASE('Y', kKey::KeyY);
    CASE('Z', kKey::KeyZ);
    CASE(VK_LWIN, kKey::Unknown);
    CASE(VK_RWIN, kKey::Unknown);
    CASE(VK_APPS, kKey::Unknown);
    CASE(VK_SLEEP, kKey::Unknown);
    CASE(VK_NUMPAD0, kKey::Unknown);
    CASE(VK_NUMPAD1, kKey::Unknown);
    CASE(VK_NUMPAD2, kKey::Unknown);
    CASE(VK_NUMPAD3, kKey::Unknown);
    CASE(VK_NUMPAD4, kKey::Unknown);
    CASE(VK_NUMPAD5, kKey::Unknown);
    CASE(VK_NUMPAD6, kKey::Unknown);
    CASE(VK_NUMPAD7, kKey::Unknown);
    CASE(VK_NUMPAD8, kKey::Unknown);
    CASE(VK_NUMPAD9, kKey::Unknown);
    CASE(VK_MULTIPLY, kKey::Unknown);
    CASE(VK_ADD, kKey::Unknown);
    CASE(VK_SEPARATOR, kKey::Unknown);
    CASE(VK_SUBTRACT, kKey::Unknown);
    CASE(VK_DECIMAL, kKey::Unknown);
    CASE(VK_DIVIDE, kKey::Unknown);
    CASE(VK_F1, kKey::KeyF1);
    CASE(VK_F2, kKey::KeyF2);
    CASE(VK_F3, kKey::KeyF3);
    CASE(VK_F4, kKey::KeyF4);
    CASE(VK_F5, kKey::KeyF5);
    CASE(VK_F6, kKey::KeyF6);
    CASE(VK_F7, kKey::KeyF7);
    CASE(VK_F8, kKey::KeyF8);
    CASE(VK_F9, kKey::KeyF9);
    CASE(VK_F10, kKey::KeyF10);
    CASE(VK_F11, kKey::KeyF11);
    CASE(VK_F12, kKey::KeyF12);
    CASE(VK_F13, kKey::KeyF13);
    CASE(VK_F14, kKey::KeyF14);
    CASE(VK_F15, kKey::KeyF15);
    CASE(VK_F16, kKey::KeyF16);
    CASE(VK_F17, kKey::KeyF17);
    CASE(VK_F18, kKey::KeyF18);
    CASE(VK_F19, kKey::KeyF19);
    CASE(VK_F20, kKey::KeyF20);
    CASE(VK_F21, kKey::KeyF21);
    CASE(VK_F22, kKey::KeyF22);
    CASE(VK_F23, kKey::KeyF23);
    CASE(VK_F24, kKey::KeyF24);
    CASE(VK_NUMLOCK, kKey::Unknown);
    CASE(VK_SCROLL, kKey::Unknown);
    //CASE(VK_OEM_NEC_EQUAL, kKey::Unknown); // same as VK_OEM_FJ_JISHO
    CASE(VK_OEM_FJ_JISHO, kKey::Unknown);
    CASE(VK_OEM_FJ_MASSHOU, kKey::Unknown);
    CASE(VK_OEM_FJ_TOUROKU, kKey::Unknown);
    CASE(VK_OEM_FJ_LOYA, kKey::Unknown);
    CASE(VK_OEM_FJ_ROYA, kKey::Unknown);
    CASE(VK_LSHIFT, kKey::Unknown);
    CASE(VK_RSHIFT, kKey::Unknown);
    CASE(VK_LCONTROL, kKey::Unknown);
    CASE(VK_RCONTROL, kKey::Unknown);
    CASE(VK_LMENU, kKey::Unknown);
    CASE(VK_RMENU, kKey::Unknown);
    CASE(VK_BROWSER_BACK, kKey::Unknown);
    CASE(VK_BROWSER_FORWARD, kKey::Unknown);
    CASE(VK_BROWSER_REFRESH, kKey::Unknown);
    CASE(VK_BROWSER_STOP, kKey::Unknown);
    CASE(VK_BROWSER_SEARCH, kKey::Unknown);
    CASE(VK_BROWSER_FAVORITES, kKey::Unknown);
    CASE(VK_BROWSER_HOME, kKey::Unknown);
    CASE(VK_VOLUME_MUTE, kKey::Unknown);
    CASE(VK_VOLUME_DOWN, kKey::Unknown);
    CASE(VK_VOLUME_UP, kKey::Unknown);
    CASE(VK_MEDIA_NEXT_TRACK, kKey::Unknown);
    CASE(VK_MEDIA_PREV_TRACK, kKey::Unknown);
    CASE(VK_MEDIA_STOP, kKey::Unknown);
    CASE(VK_MEDIA_PLAY_PAUSE, kKey::Unknown);
    CASE(VK_LAUNCH_MAIL, kKey::Unknown);
    CASE(VK_LAUNCH_MEDIA_SELECT, kKey::Unknown);
    CASE(VK_LAUNCH_APP1, kKey::Unknown);
    CASE(VK_LAUNCH_APP2, kKey::Unknown);
    CASE(VK_OEM_1, kKey::Unknown);
    CASE(VK_OEM_PLUS, kKey::Unknown);
    CASE(VK_OEM_COMMA, kKey::Unknown);
    CASE(VK_OEM_MINUS, kKey::Unknown);
    CASE(VK_OEM_PERIOD, kKey::Unknown);
    CASE(VK_OEM_2, kKey::Unknown);
    CASE(VK_OEM_3, kKey::Unknown);
    CASE(VK_OEM_4, kKey::Unknown);
    CASE(VK_OEM_5, kKey::Unknown);
    CASE(VK_OEM_6, kKey::Unknown);
    CASE(VK_OEM_7, kKey::Unknown);
    CASE(VK_OEM_8, kKey::Unknown);
    CASE(VK_OEM_AX, kKey::Unknown);
    CASE(VK_OEM_102, kKey::Unknown);
    CASE(VK_ICO_HELP, kKey::Unknown);
    CASE(VK_ICO_00, kKey::Unknown);
    CASE(VK_PROCESSKEY, kKey::Unknown);
    CASE(VK_ICO_CLEAR, kKey::Unknown);
    CASE(VK_PACKET, kKey::Unknown);
    CASE(VK_OEM_RESET, kKey::Unknown);
    CASE(VK_OEM_JUMP, kKey::Unknown);
    CASE(VK_OEM_PA1, kKey::Unknown);
    CASE(VK_OEM_PA2, kKey::Unknown);
    CASE(VK_OEM_PA3, kKey::Unknown);
    CASE(VK_OEM_WSCTRL, kKey::Unknown);
    CASE(VK_OEM_CUSEL, kKey::Unknown);
    CASE(VK_OEM_ATTN, kKey::Unknown);
    CASE(VK_OEM_FINISH, kKey::Unknown);
    CASE(VK_OEM_COPY, kKey::Unknown);
    CASE(VK_OEM_AUTO, kKey::Unknown);
    CASE(VK_OEM_ENLW, kKey::Unknown);
    CASE(VK_OEM_BACKTAB, kKey::Unknown);
    CASE(VK_ATTN, kKey::Unknown);
    CASE(VK_CRSEL, kKey::Unknown);
    CASE(VK_EXSEL, kKey::Unknown);
    CASE(VK_EREOF, kKey::Unknown);
    CASE(VK_PLAY, kKey::Unknown);
    CASE(VK_ZOOM, kKey::Unknown);
    CASE(VK_NONAME, kKey::Unknown);
    CASE(VK_PA1, kKey::Unknown);
    CASE(VK_OEM_CLEAR, kKey::Unknown);
#endif
    default: 
        return kKey::Unknown;
    }
}
