I personnaly use boost::bimap which may be a bit an overkill.
No need to compile it just needs plain headers.
Code: Select all
// don't forget to instantiate static members
...
// replace left by right and invert the types (EKEY_CODE and stringw) to produce the inverse function
const stringw&
CEventMapping::keyCodeToString(const irr::EKEY_CODE& keyCode)
{
try {
//TMappings::left_mconst_iterator _keyMap.left.find(keyCode);
return _keyMap.left.at(keyCode);
}
catch( std::out_of_range & e ) {
_ERROR << "Couldn't find keyCode associated with" << keyCode << "in keyCodeToString";
return _unknown;
}
}
void
CEventMapping::initializeBimaps()
{
_keyMap.insert( TKeyAssociation(KEY_LBUTTON,L"KEY_LBUTTON") );
_keyMap.insert( TKeyAssociation(KEY_RBUTTON,L"KEY_RBUTTON") );
_keyMap.insert( TKeyAssociation(KEY_CANCEL,L"KEY_CANCEL") );
_keyMap.insert( TKeyAssociation(KEY_MBUTTON,L"KEY_MBUTTON") );
_keyMap.insert( TKeyAssociation(KEY_XBUTTON1,L"KEY_XBUTTON1") );
_keyMap.insert( TKeyAssociation(KEY_XBUTTON2,L"KEY_XBUTTON2") );
_keyMap.insert( TKeyAssociation(KEY_BACK,L"KEY_BACK") );
_keyMap.insert( TKeyAssociation(KEY_TAB,L"KEY_TAB") );
_keyMap.insert( TKeyAssociation(KEY_CLEAR,L"KEY_CLEAR") );
_keyMap.insert( TKeyAssociation(KEY_RETURN,L"KEY_RETURN") );
_keyMap.insert( TKeyAssociation(KEY_SHIFT,L"KEY_SHIFT") );
_keyMap.insert( TKeyAssociation(KEY_CONTROL,L"KEY_CONTROL") );
_keyMap.insert( TKeyAssociation(KEY_MENU,L"KEY_MENU") );
_keyMap.insert( TKeyAssociation(KEY_PAUSE,L"KEY_PAUSE") );
_keyMap.insert( TKeyAssociation(KEY_CAPITAL,L"KEY_CAPITAL") );
_keyMap.insert( TKeyAssociation(KEY_KANA,L"KEY_KANA") );
_keyMap.insert( TKeyAssociation(KEY_HANGUEL,L"KEY_HANGUEL") );
_keyMap.insert( TKeyAssociation(KEY_HANGUL,L"KEY_HANGUL") );
_keyMap.insert( TKeyAssociation(KEY_JUNJA,L"KEY_JUNJA") );
_keyMap.insert( TKeyAssociation(KEY_FINAL,L"KEY_FINAL") );
_keyMap.insert( TKeyAssociation(KEY_KANJI,L"KEY_KANJI") );
_keyMap.insert( TKeyAssociation(KEY_ESCAPE,L"KEY_ESCAPE") );
_keyMap.insert( TKeyAssociation(KEY_CONVERT,L"KEY_CONVERT") );
_keyMap.insert( TKeyAssociation(KEY_NONCONVERT,L"KEY_NONCONVERT") );
_keyMap.insert( TKeyAssociation(KEY_ACCEPT,L"KEY_ACCEPT") );
_keyMap.insert( TKeyAssociation(KEY_MODECHANGE,L"KEY_MODECHANGE") );
_keyMap.insert( TKeyAssociation(KEY_SPACE,L"KEY_SPACE") );
_keyMap.insert( TKeyAssociation(KEY_PRIOR,L"KEY_PRIOR") );
_keyMap.insert( TKeyAssociation(KEY_NEXT,L"KEY_NEXT") );
_keyMap.insert( TKeyAssociation(KEY_END,L"KEY_END") );
_keyMap.insert( TKeyAssociation(KEY_HOME,L"KEY_HOME") );
_keyMap.insert( TKeyAssociation(KEY_LEFT,L"KEY_LEFT") );
_keyMap.insert( TKeyAssociation(KEY_UP,L"KEY_UP") );
_keyMap.insert( TKeyAssociation(KEY_RIGHT,L"KEY_RIGHT") );
_keyMap.insert( TKeyAssociation(KEY_DOWN,L"KEY_DOWN") );
_keyMap.insert( TKeyAssociation(KEY_SELECT,L"KEY_SELECT") );
_keyMap.insert( TKeyAssociation(KEY_PRINT,L"KEY_PRINT") );
_keyMap.insert( TKeyAssociation(KEY_PRINT,L"KEY_DOWN") );
_keyMap.insert( TKeyAssociation(KEY_EXECUT,L"KEY_EXECUT") );
_keyMap.insert( TKeyAssociation(KEY_SNAPSHOT,L"KEY_SNAPSHOT") );
_keyMap.insert( TKeyAssociation(KEY_INSERT,L"KEY_INSERT") );
_keyMap.insert( TKeyAssociation(KEY_DELETE,L"KEY_DELETE") );
_keyMap.insert( TKeyAssociation(KEY_HELP,L"KEY_HELP") );
_keyMap.insert( TKeyAssociation(KEY_INSERT,L"KEY_INSERT") );
_keyMap.insert( TKeyAssociation(KEY_KEY_0,L"KEY_KEY_0") );
_keyMap.insert( TKeyAssociation(KEY_KEY_1,L"KEY_KEY_1") );
_keyMap.insert( TKeyAssociation(KEY_KEY_2,L"KEY_KEY_2") );
_keyMap.insert( TKeyAssociation(KEY_KEY_3,L"KEY_KEY_3") );
_keyMap.insert( TKeyAssociation(KEY_KEY_4,L"KEY_KEY_4") );
_keyMap.insert( TKeyAssociation(KEY_KEY_5,L"KEY_KEY_5") );
_keyMap.insert( TKeyAssociation(KEY_KEY_6,L"KEY_KEY_6") );
_keyMap.insert( TKeyAssociation(KEY_KEY_7,L"KEY_KEY_7") );
_keyMap.insert( TKeyAssociation(KEY_KEY_8,L"KEY_KEY_8") );
_keyMap.insert( TKeyAssociation(KEY_KEY_9,L"KEY_KEY_9") );
_keyMap.insert( TKeyAssociation(KEY_KEY_A,L"KEY_KEY_A") );
_keyMap.insert( TKeyAssociation(KEY_KEY_B,L"KEY_KEY_B") );
_keyMap.insert( TKeyAssociation(KEY_KEY_C,L"KEY_KEY_C") );
_keyMap.insert( TKeyAssociation(KEY_KEY_D,L"KEY_KEY_D") );
_keyMap.insert( TKeyAssociation(KEY_KEY_E,L"KEY_KEY_E") );
_keyMap.insert( TKeyAssociation(KEY_KEY_F,L"KEY_KEY_F") );
_keyMap.insert( TKeyAssociation(KEY_KEY_G,L"KEY_KEY_G") );
_keyMap.insert( TKeyAssociation(KEY_KEY_H,L"KEY_KEY_H") );
_keyMap.insert( TKeyAssociation(KEY_KEY_I,L"KEY_KEY_I") );
_keyMap.insert( TKeyAssociation(KEY_KEY_J,L"KEY_KEY_J") );
_keyMap.insert( TKeyAssociation(KEY_KEY_K,L"KEY_KEY_K") );
_keyMap.insert( TKeyAssociation(KEY_KEY_L,L"KEY_KEY_L") );
_keyMap.insert( TKeyAssociation(KEY_KEY_M,L"KEY_KEY_M") );
_keyMap.insert( TKeyAssociation(KEY_KEY_N,L"KEY_KEY_N") );
_keyMap.insert( TKeyAssociation(KEY_KEY_O,L"KEY_KEY_O") );
_keyMap.insert( TKeyAssociation(KEY_KEY_P,L"KEY_KEY_P") );
_keyMap.insert( TKeyAssociation(KEY_KEY_Q,L"KEY_KEY_Q") );
_keyMap.insert( TKeyAssociation(KEY_KEY_R,L"KEY_KEY_R") );
_keyMap.insert( TKeyAssociation(KEY_KEY_S,L"KEY_KEY_S") );
_keyMap.insert( TKeyAssociation(KEY_KEY_T,L"KEY_KEY_T") );
_keyMap.insert( TKeyAssociation(KEY_KEY_U,L"KEY_KEY_U") );
_keyMap.insert( TKeyAssociation(KEY_KEY_V,L"KEY_KEY_V") );
_keyMap.insert( TKeyAssociation(KEY_KEY_W,L"KEY_KEY_W") );
_keyMap.insert( TKeyAssociation(KEY_KEY_X,L"KEY_KEY_X") );
_keyMap.insert( TKeyAssociation(KEY_KEY_Y,L"KEY_KEY_Y") );
_keyMap.insert( TKeyAssociation(KEY_KEY_Z,L"KEY_KEY_Z") );
_keyMap.insert( TKeyAssociation(KEY_LWIN,L"KEY_LWIN") );
_keyMap.insert( TKeyAssociation(KEY_RWIN,L"KEY_RWIN") );
_keyMap.insert( TKeyAssociation(KEY_APPS,L"KEY_APPS") );
_keyMap.insert( TKeyAssociation(KEY_SLEEP,L"KEY_SLEEP") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD0,L"KEY_NUMPAD0") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD1,L"KEY_NUMPAD1") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD2,L"KEY_NUMPAD2") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD3,L"KEY_NUMPAD3") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD4,L"KEY_NUMPAD4") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD5,L"KEY_NUMPAD5") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD6,L"KEY_NUMPAD6") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD7,L"KEY_NUMPAD7") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD8,L"KEY_NUMPAD8") );
_keyMap.insert( TKeyAssociation(KEY_NUMPAD9,L"KEY_NUMPAD9") );
_keyMap.insert( TKeyAssociation(KEY_MULTIPLY,L"KEY_MULTIPLY") );
_keyMap.insert( TKeyAssociation(KEY_ADD,L"KEY_ADD") );
_keyMap.insert( TKeyAssociation(KEY_SEPARATOR,L"KEY_SEPARATOR") );
_keyMap.insert( TKeyAssociation(KEY_SUBTRACT,L"KEY_SUBTRACT") );
_keyMap.insert( TKeyAssociation(KEY_DECIMAL,L"KEY_DECIMAL") );
_keyMap.insert( TKeyAssociation(KEY_DIVIDE,L"KEY_DIVIDE") );
_keyMap.insert( TKeyAssociation(KEY_F1,L"KEY_F1") );
_keyMap.insert( TKeyAssociation(KEY_F2,L"KEY_F2") );
_keyMap.insert( TKeyAssociation(KEY_F3,L"KEY_F3") );
_keyMap.insert( TKeyAssociation(KEY_F4,L"KEY_F4") );
_keyMap.insert( TKeyAssociation(KEY_F5,L"KEY_F5") );
_keyMap.insert( TKeyAssociation(KEY_F6,L"KEY_F6") );
_keyMap.insert( TKeyAssociation(KEY_F7,L"KEY_F7") );
_keyMap.insert( TKeyAssociation(KEY_F8,L"KEY_F8") );
_keyMap.insert( TKeyAssociation(KEY_F9,L"KEY_F9") );
_keyMap.insert( TKeyAssociation(KEY_F10,L"KEY_F10") );
_keyMap.insert( TKeyAssociation(KEY_F11,L"KEY_F11") );
_keyMap.insert( TKeyAssociation(KEY_F12,L"KEY_F12") );
_keyMap.insert( TKeyAssociation(KEY_F13,L"KEY_F13") );
_keyMap.insert( TKeyAssociation(KEY_F14,L"KEY_F14") );
_keyMap.insert( TKeyAssociation(KEY_F15,L"KEY_F15") );
_keyMap.insert( TKeyAssociation(KEY_F16,L"KEY_F16") );
_keyMap.insert( TKeyAssociation(KEY_F17,L"KEY_F17") );
_keyMap.insert( TKeyAssociation(KEY_F18,L"KEY_F18") );
_keyMap.insert( TKeyAssociation(KEY_F19,L"KEY_F19") );
_keyMap.insert( TKeyAssociation(KEY_F20,L"KEY_F20") );
_keyMap.insert( TKeyAssociation(KEY_F21,L"KEY_F21") );
_keyMap.insert( TKeyAssociation(KEY_F22,L"KEY_F22") );
_keyMap.insert( TKeyAssociation(KEY_F23,L"KEY_F23") );
_keyMap.insert( TKeyAssociation(KEY_F24,L"KEY_F24") );
_keyMap.insert( TKeyAssociation(KEY_NUMLOCK,L"KEY_NUMLOCK") );
_keyMap.insert( TKeyAssociation(KEY_SCROLL,L"KEY_SCROLL") );
_keyMap.insert( TKeyAssociation(KEY_LSHIFT,L"KEY_LSHIFT") );
_keyMap.insert( TKeyAssociation(KEY_RSHIFT,L"KEY_RSHIFT") );
_keyMap.insert( TKeyAssociation(KEY_LCONTROL,L"KEY_LCONTROL") );
_keyMap.insert( TKeyAssociation(KEY_RCONTROL,L"KEY_RCONTROL") );
_keyMap.insert( TKeyAssociation(KEY_LMENU,L"KEY_LMENU") );
_keyMap.insert( TKeyAssociation(KEY_RMENU,L"KEY_RMENU") );
_keyMap.insert( TKeyAssociation(KEY_PLUS,L"KEY_PLUS") );
_keyMap.insert( TKeyAssociation(KEY_COMMA,L"KEY_COMMA") );
_keyMap.insert( TKeyAssociation(KEY_MINUS,L"KEY_MINUS") );
_keyMap.insert( TKeyAssociation(KEY_PERIOD,L"KEY_PERIOD") );
_keyMap.insert( TKeyAssociation(KEY_ATTN,L"KEY_ATTN") );
_keyMap.insert( TKeyAssociation(KEY_CRSEL,L"KEY_CRSEL") );
_keyMap.insert( TKeyAssociation(KEY_CRSEL,L"KEY_CRSEL") );
_keyMap.insert( TKeyAssociation(KEY_EXSEL,L"KEY_EXSEL") );
_keyMap.insert( TKeyAssociation(KEY_EREOF,L"KEY_EREOF") );
_keyMap.insert( TKeyAssociation(KEY_PLAY,L"KEY_PLAY") );
_keyMap.insert( TKeyAssociation(KEY_ZOOM,L"KEY_ZOOM") );
_keyMap.insert( TKeyAssociation(KEY_PA1,L"KEY_PA1") );
_keyMap.insert( TKeyAssociation(KEY_OEM_CLEAR,L"KEY_OEM_CLEAR") );
}