diff --git a/source/ps/Hotkey.cpp b/source/ps/Hotkey.cpp new file mode 100755 index 0000000000..dcae663a95 --- /dev/null +++ b/source/ps/Hotkey.cpp @@ -0,0 +1,222 @@ +#include "precompiled.h" + +#include "Hotkey.h" +#include "input.h" +#include "ConfigDB.h" + +bool hotkeys[HOTKEY_LAST]; +extern bool keys[SDLK_LAST]; +extern bool mouseButtons[5]; + +struct SHotkeyMapping +{ + int mapsTo; + std::vector requires; +}; + +static std::vector hotkeyMap[SDLK_LAST + 5]; + +const int MOUSE_LEFT = SDLK_LAST + SDL_BUTTON_LEFT; +const int MOUSE_RIGHT = SDLK_LAST + SDL_BUTTON_RIGHT; +const int MOUSE_MIDDLE = SDLK_LAST + SDL_BUTTON_MIDDLE; +const int MOUSE_WHEELUP = SDLK_LAST + SDL_BUTTON_WHEELUP; +const int MOUSE_WHEELDOWN = SDLK_LAST + SDL_BUTTON_WHEELDOWN; + +struct SHotkeyInfo +{ + int code; + const char* name; + int defaultmapping1, defaultmapping2; +}; + +static SHotkeyInfo hotkeyInfo[] = +{ + { HOTKEY_EXIT, "exit", SDLK_ESCAPE, 0 }, + { HOTKEY_SCREENSHOT, "screenshot", SDLK_PRINT, 0 }, + { HOTKEY_WIREFRAME, "wireframe", SDLK_w, 0 }, + { HOTKEY_CAMERA_RESET, "camera.reset", SDLK_h, 0 }, + { HOTKEY_CAMERA_ZOOM_IN, "camera.zoom.in", SDLK_PLUS, SDLK_KP_PLUS }, + { HOTKEY_CAMERA_ZOOM_OUT, "camera.zoom.out", SDLK_MINUS, SDLK_KP_MINUS }, + { HOTKEY_CAMERA_ZOOM_WHEEL_IN, "camera.zoom.wheel.in", MOUSE_WHEELUP, 0 }, + { HOTKEY_CAMERA_ZOOM_WHEEL_OUT, "camera.zoom.wheel.out", MOUSE_WHEELDOWN, 0 }, + { HOTKEY_CAMERA_ROTATE, "camera.rotate", 0, 0 }, + { HOTKEY_CAMERA_PAN, "camera.pan", MOUSE_MIDDLE, 0 }, + { HOTKEY_CAMERA_PAN_LEFT, "camera.pan.left", SDLK_LEFT, 0 }, + { HOTKEY_CAMERA_PAN_RIGHT, "camera.pan.right", SDLK_RIGHT, 0 }, + { HOTKEY_CAMERA_PAN_FORWARD, "camera.pan.forward", SDLK_UP, 0 }, + { HOTKEY_CAMERA_PAN_BACKWARD, "camera.pan.backward", SDLK_DOWN, 0 }, + { HOTKEY_CONSOLE_TOGGLE, "console.toggle", SDLK_F1, 0 }, + { HOTKEY_SELECTION_ADD, "selection.add", SDLK_LSHIFT, SDLK_RSHIFT }, + { HOTKEY_SELECTION_REMOVE, "selection.remove", SDLK_LCTRL, SDLK_RCTRL }, + { HOTKEY_SELECTION_GROUP_ADD, "selection.group.add", SDLK_LSHIFT, SDLK_RSHIFT }, + { HOTKEY_SELECTION_GROUP_SAVE, "selection.group.save", SDLK_LCTRL, SDLK_RCTRL }, + { HOTKEY_SELECTION_GROUP_SNAP, "selection.group.snap", SDLK_LALT, SDLK_RALT }, + { HOTKEY_SELECTION_SNAP, "selection.snap", SDLK_HOME, 0 }, + { HOTKEY_CONTEXTORDER_NEXT, "contextorder.next", SDLK_RIGHTBRACKET, 0 }, + { HOTKEY_CONTEXTORDER_PREVIOUS, "contextorder.previous", SDLK_LEFTBRACKET, 0 }, + { HOTKEY_HIGHLIGHTALL, "highlightall", SDLK_o, 0 } +}; + +void loadHotkeys() +{ + initKeyNameMap(); + + CParser multikeyParser; + multikeyParser.InputTaskType( "multikey", "<_$value_+_>_$value" ); + + for( int i = 0; i < HOTKEY_LAST; i++ ) + { + CStr hotkeyname( "hotkey." ); + hotkeyname += hotkeyInfo[i].name; + + CConfigValueSet* binding = g_ConfigDB.GetValues( CFG_SYSTEM, hotkeyname ); + + if( binding ) + { + int mapping; + + CConfigValueSet::iterator it; + + // Iterate through the bindings for this event... + + for( it = binding->begin(); it != binding->end(); it++ ) + { + std::string hotkey; + if( it->GetString( hotkey ) ) + { + std::vector keyCombination; + + CParserLine multikeyIdentifier; + multikeyIdentifier.ParseString( multikeyParser, hotkey ); + + // Iterate through multiple-key bindings (e.g. Ctrl+I) + + for( size_t t = 0; t < multikeyIdentifier.GetArgCount(); t++ ) + { + + if( multikeyIdentifier.GetArgString( (int)t, hotkey ) ) + { + mapping = getKeyCode( hotkey ); // Attempt decode as key name + if( !mapping ) + if( !it->GetInt( mapping ) ) // Attempt decode as key code + continue; + keyCombination.push_back( mapping ); + } + } + + std::vector::iterator itKey, itKey2; + + SHotkeyMapping bind; + + for( itKey = keyCombination.begin(); itKey != keyCombination.end(); itKey++ ) + { + bind.mapsTo = i; + bind.requires.clear(); + for( itKey2 = keyCombination.begin(); itKey2 != keyCombination.end(); itKey2++ ) + { + // Push any auxiliary keys. + if( itKey != itKey2 ) + bind.requires.push_back( *itKey2 ); + } + hotkeyMap[*itKey].push_back( bind ); + } + } + } + } + else + { + SHotkeyMapping bind[2]; + bind[0].mapsTo = i; + bind[1].mapsTo = i; + bind[0].requires.clear(); + bind[1].requires.clear(); + hotkeyMap[ hotkeyInfo[i].defaultmapping1 ].push_back( bind[0] ); + if( hotkeyInfo[i].defaultmapping2 ) + hotkeyMap[ hotkeyInfo[i].defaultmapping2 ].push_back( bind[1] ); + } + } +} + +int hotkeyInputHandler( const SDL_Event* ev ) +{ + int keycode; + + switch( ev->type ) + { + case SDL_KEYDOWN: + case SDL_KEYUP: + keycode = (int)ev->key.keysym.sym; + break; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + keycode = SDLK_LAST + (int)ev->button.button; + break; + default: + return( EV_PASS ); + } + + std::vector::iterator it; + SDL_Event hotkeyNotification; + + if( ( ev->type == SDL_KEYDOWN ) || ( ev->type == SDL_MOUSEBUTTONDOWN ) ) + { + for( it = hotkeyMap[keycode].begin(); it < hotkeyMap[keycode].end(); it++ ) + { + // Check to see if all auxiliary keys are down + + std::vector::iterator itKey; + bool accept = true; + + for( itKey = it->requires.begin(); itKey != it->requires.end(); itKey++ ) + { + if( *itKey < SDLK_LAST ) + { + if( !keys[*itKey] ) accept = false; + } + else + { + if( !mouseButtons[(*itKey)-SDLK_LAST] ) accept = false; + } + } + + if( accept ) + { + hotkeys[it->mapsTo] = true; + hotkeyNotification.type = SDL_HOTKEYDOWN; + hotkeyNotification.user.code = it->mapsTo; + SDL_PushEvent( &hotkeyNotification ); + } + } + } + else + { + for( it = hotkeyMap[keycode].begin(); it < hotkeyMap[keycode].end(); it++ ) + { + // Check to see if all auxiliary keys are down + + std::vector::iterator itKey; + bool accept = true; + + for( itKey = it->requires.begin(); itKey != it->requires.end(); itKey++ ) + { + if( *itKey < SDLK_LAST ) + { + if( !keys[*itKey] ) accept = false; + } + else + { + if( !mouseButtons[(*itKey)-SDLK_LAST] ) accept = false; + } + } + + if( accept ) + { + hotkeys[it->mapsTo] = false; + hotkeyNotification.type = SDL_HOTKEYUP; + hotkeyNotification.user.code = it->mapsTo; + SDL_PushEvent( &hotkeyNotification ); + } + } + } + return( EV_PASS ); +} diff --git a/source/ps/Hotkey.h b/source/ps/Hotkey.h new file mode 100755 index 0000000000..32ff97e7aa --- /dev/null +++ b/source/ps/Hotkey.h @@ -0,0 +1,60 @@ +// Hotkey.h +// +// Constant definitions and a couple of exports for the hotkey processor +// +// Mark Thompson (mot20@cam.ac.uk / mark@wildfiregames.com) + +// Adding a hotkey: +// +// - Define your constant in the enum, just below; +// - Add an entry to hotkeyInfo[], in Hotkey.cpp +// first column is this constant, second is the config string (minus 'hotkey.') it maps to +// third and fourth are the default keys, used if the config file doesn't contain that string. +// - Create an input handler for SDL_HOTKEYDOWN, SDL_HOTKEYUP, or poll the hotkeys[] array. +// For SDL_HOTKEYDOWN, SDL_HOTKEYUP, the constant is passed in as ev->user.code. +// - Add some bindings to the config file. + +#include "precompiled.h" +#include "sdl.h" +#include "CStr.h" + +const int SDL_HOTKEYDOWN = SDL_USEREVENT; +const int SDL_HOTKEYUP = SDL_USEREVENT + 1; + +enum +{ + HOTKEY_EXIT, + HOTKEY_SCREENSHOT, + HOTKEY_WIREFRAME, + HOTKEY_CAMERA_RESET, + HOTKEY_CAMERA_ZOOM_IN, + HOTKEY_CAMERA_ZOOM_OUT, + HOTKEY_CAMERA_ZOOM_WHEEL_IN, + HOTKEY_CAMERA_ZOOM_WHEEL_OUT, + HOTKEY_CAMERA_ROTATE, + HOTKEY_CAMERA_PAN, + HOTKEY_CAMERA_PAN_LEFT, + HOTKEY_CAMERA_PAN_RIGHT, + HOTKEY_CAMERA_PAN_FORWARD, + HOTKEY_CAMERA_PAN_BACKWARD, + HOTKEY_CONSOLE_TOGGLE, + HOTKEY_SELECTION_ADD, + HOTKEY_SELECTION_REMOVE, + HOTKEY_SELECTION_GROUP_ADD, + HOTKEY_SELECTION_GROUP_SAVE, + HOTKEY_SELECTION_GROUP_SNAP, + HOTKEY_SELECTION_SNAP, + HOTKEY_CONTEXTORDER_NEXT, + HOTKEY_CONTEXTORDER_PREVIOUS, + HOTKEY_HIGHLIGHTALL, + HOTKEY_LAST, +}; + +void loadHotkeys(); +int hotkeyInputHandler( const SDL_Event* ev ); + +void initKeyNameMap(); +CStr getKeyName( int keycode ); +int getKeyCode( CStr keyname ); + +extern bool hotkeys[HOTKEY_LAST]; \ No newline at end of file diff --git a/source/ps/KeyName.cpp b/source/ps/KeyName.cpp new file mode 100755 index 0000000000..b81b753955 --- /dev/null +++ b/source/ps/KeyName.cpp @@ -0,0 +1,296 @@ +// Ooh, a file of keynames. Fun. + +#include "precompiled.h" +#include +#include "CStr.h" + +static std::map keymap; + +struct SKeycodeMapping +{ + int keycode; + const char* keyname; + const char* altkeyname; +}; + +static SKeycodeMapping keycodeMapping[] = +{ + /* Just a tad friendlier than SDL_GetKeyName's name */ + { SDLK_BACKSPACE, "Backspace", "BkSp" }, + { SDLK_TAB, "Tab", 0 }, + { SDLK_CLEAR, "Clear", 0 }, // ? + { SDLK_RETURN, "Return", "Ret" }, + { SDLK_PAUSE, "Pause", 0 }, // ? + { SDLK_ESCAPE, "Escape", "Esc" }, + { SDLK_SPACE, "Space", "Spc" }, + { SDLK_EXCLAIM, "!", "Exclaim" }, + { SDLK_QUOTEDBL, "\"", "DoubleQuote" }, + { SDLK_HASH, "#", "Hash" }, + { SDLK_DOLLAR, "$", "Dollar" }, + { SDLK_AMPERSAND, "&", "Ampersand" }, + { SDLK_QUOTE, "'", "SingleQuote" }, + { SDLK_LEFTPAREN, "(", "LeftParen" }, + { SDLK_RIGHTPAREN, ")", "RightParen" }, + { SDLK_ASTERISK, "*", "Asterisk" }, + { SDLK_PLUS, "+", "Plus" }, + { SDLK_COMMA, ",", "Comma" }, + { SDLK_MINUS, "-", "Minus" }, + { SDLK_PERIOD, ".", "Period" }, + { SDLK_SLASH, "/", "ForwardSlash" }, + { SDLK_0, "0", 0 }, + { SDLK_1, "1", 0 }, + { SDLK_2, "2", 0 }, + { SDLK_3, "3", 0 }, + { SDLK_4, "4", 0 }, + { SDLK_5, "5", 0 }, + { SDLK_6, "6", 0 }, + { SDLK_7, "7", 0 }, + { SDLK_8, "8", 0 }, + { SDLK_9, "9", 0 }, + { SDLK_COLON, ":", "Colon" }, + { SDLK_SEMICOLON, ";", "Semicolon" }, + { SDLK_LESS, "<", "LessThan" }, + { SDLK_EQUALS, "=", "Equals" }, + { SDLK_GREATER, ">", "GreaterThan" }, + { SDLK_QUESTION, "?", "Question" }, + { SDLK_AT, "@", "At" }, + { SDLK_LEFTBRACKET, "[", "LeftBracket" }, + { SDLK_BACKSLASH, "\\", "BackSlash" }, + { SDLK_RIGHTBRACKET, "]", "RightBracket" }, + { SDLK_CARET, "^", "Caret", }, + { SDLK_UNDERSCORE, "_", "Underscore" }, + { SDLK_BACKQUOTE, "`", "BackQuote" }, + { SDLK_a, "A", 0 }, + { SDLK_b, "B", 0 }, + { SDLK_c, "C", 0 }, + { SDLK_d, "D", 0 }, + { SDLK_e, "E", 0 }, + { SDLK_f, "F", 0 }, + { SDLK_g, "G", 0 }, + { SDLK_h, "H", 0 }, + { SDLK_i, "I", 0 }, + { SDLK_j, "J", 0 }, + { SDLK_k, "K", 0 }, + { SDLK_l, "L", 0 }, + { SDLK_m, "M", 0 }, + { SDLK_n, "N", 0 }, + { SDLK_o, "O", 0 }, + { SDLK_p, "P", 0 }, + { SDLK_q, "Q", 0 }, + { SDLK_r, "R", 0 }, + { SDLK_s, "S", 0 }, + { SDLK_t, "T", 0 }, + { SDLK_u, "U", 0 }, + { SDLK_v, "V", 0 }, + { SDLK_w, "W", 0 }, + { SDLK_x, "X", 0 }, + { SDLK_y, "Y", 0 }, + { SDLK_z, "Z", 0 }, + { SDLK_DELETE, "Delete", "Del" }, +/* + { SDLK_WORLD_0, "world 0" }, + { SDLK_WORLD_1, "world 1" }, + { SDLK_WORLD_2, "world 2" }, + { SDLK_WORLD_3, "world 3" }, + { SDLK_WORLD_4, "world 4" }, + { SDLK_WORLD_5, "world 5" }, + { SDLK_WORLD_6, "world 6" }, + { SDLK_WORLD_7, "world 7" }, + { SDLK_WORLD_8, "world 8" }, + { SDLK_WORLD_9, "world 9" }, + { SDLK_WORLD_10, "world 10" }, + { SDLK_WORLD_11, "world 11" }, + { SDLK_WORLD_12, "world 12" }, + { SDLK_WORLD_13, "world 13" }, + { SDLK_WORLD_14, "world 14" }, + { SDLK_WORLD_15, "world 15" }, + { SDLK_WORLD_16, "world 16" }, + { SDLK_WORLD_17, "world 17" }, + { SDLK_WORLD_18, "world 18" }, + { SDLK_WORLD_19, "world 19" }, + { SDLK_WORLD_20, "world 20" }, + { SDLK_WORLD_21, "world 21" }, + { SDLK_WORLD_22, "world 22" }, + { SDLK_WORLD_23, "world 23" }, + { SDLK_WORLD_24, "world 24" }, + { SDLK_WORLD_25, "world 25" }, + { SDLK_WORLD_26, "world 26" }, + { SDLK_WORLD_27, "world 27" }, + { SDLK_WORLD_28, "world 28" }, + { SDLK_WORLD_29, "world 29" }, + { SDLK_WORLD_30, "world 30" }, + { SDLK_WORLD_31, "world 31" }, + { SDLK_WORLD_32, "world 32" }, + { SDLK_WORLD_33, "world 33" }, + { SDLK_WORLD_34, "world 34" }, + { SDLK_WORLD_35, "world 35" }, + { SDLK_WORLD_36, "world 36" }, + { SDLK_WORLD_37, "world 37" }, + { SDLK_WORLD_38, "world 38" }, + { SDLK_WORLD_39, "world 39" }, + { SDLK_WORLD_40, "world 40" }, + { SDLK_WORLD_41, "world 41" }, + { SDLK_WORLD_42, "world 42" }, + { SDLK_WORLD_43, "world 43" }, + { SDLK_WORLD_44, "world 44" }, + { SDLK_WORLD_45, "world 45" }, + { SDLK_WORLD_46, "world 46" }, + { SDLK_WORLD_47, "world 47" }, + { SDLK_WORLD_48, "world 48" }, + { SDLK_WORLD_49, "world 49" }, + { SDLK_WORLD_50, "world 50" }, + { SDLK_WORLD_51, "world 51" }, + { SDLK_WORLD_52, "world 52" }, + { SDLK_WORLD_53, "world 53" }, + { SDLK_WORLD_54, "world 54" }, + { SDLK_WORLD_55, "world 55" }, + { SDLK_WORLD_56, "world 56" }, + { SDLK_WORLD_57, "world 57" }, + { SDLK_WORLD_58, "world 58" }, + { SDLK_WORLD_59, "world 59" }, + { SDLK_WORLD_60, "world 60" }, + { SDLK_WORLD_61, "world 61" }, + { SDLK_WORLD_62, "world 62" }, + { SDLK_WORLD_63, "world 63" }, + { SDLK_WORLD_64, "world 64" }, + { SDLK_WORLD_65, "world 65" }, + { SDLK_WORLD_66, "world 66" }, + { SDLK_WORLD_67, "world 67" }, + { SDLK_WORLD_68, "world 68" }, + { SDLK_WORLD_69, "world 69" }, + { SDLK_WORLD_70, "world 70" }, + { SDLK_WORLD_71, "world 71" }, + { SDLK_WORLD_72, "world 72" }, + { SDLK_WORLD_73, "world 73" }, + { SDLK_WORLD_74, "world 74" }, + { SDLK_WORLD_75, "world 75" }, + { SDLK_WORLD_76, "world 76" }, + { SDLK_WORLD_77, "world 77" }, + { SDLK_WORLD_78, "world 78" }, + { SDLK_WORLD_79, "world 79" }, + { SDLK_WORLD_80, "world 80" }, + { SDLK_WORLD_81, "world 81" }, + { SDLK_WORLD_82, "world 82" }, + { SDLK_WORLD_83, "world 83" }, + { SDLK_WORLD_84, "world 84" }, + { SDLK_WORLD_85, "world 85" }, + { SDLK_WORLD_86, "world 86" }, + { SDLK_WORLD_87, "world 87" }, + { SDLK_WORLD_88, "world 88" }, + { SDLK_WORLD_89, "world 89" }, + { SDLK_WORLD_90, "world 90" }, + { SDLK_WORLD_91, "world 91" }, + { SDLK_WORLD_92, "world 92" }, + { SDLK_WORLD_93, "world 93" }, + { SDLK_WORLD_94, "world 94" }, + { SDLK_WORLD_95, "world 95" }, +*/ + { SDLK_KP0, "Numpad 0", "Num0" }, + { SDLK_KP1, "Numpad 1", "Num1" }, + { SDLK_KP2, "Numpad 2", "Num2" }, + { SDLK_KP3, "Numpad 3", "Num3" }, + { SDLK_KP4, "Numpad 4", "Num4" }, + { SDLK_KP5, "Numpad 5", "Num5" }, + { SDLK_KP6, "Numpad 6", "Num6" }, + { SDLK_KP7, "Numpad 7", "Num7" }, + { SDLK_KP8, "Numpad 8", "Num8" }, + { SDLK_KP9, "Numpad 9", "Num9" }, + { SDLK_KP_PERIOD, "Numpad .", "NumPoint" }, + { SDLK_KP_DIVIDE, "Numpad /", "NumDivide" }, + { SDLK_KP_MULTIPLY, "Numpad *", "NumMultiply" }, + { SDLK_KP_MINUS, "Numpad -", "NumMinus" }, + { SDLK_KP_PLUS, "Numpad +", "NumPlus" }, + { SDLK_KP_ENTER, "Numpad Enter", "NumEnter" }, + { SDLK_KP_EQUALS, "Numpad =", "NumEquals" }, //? + + { SDLK_UP, "Arrow Up", "UpArrow" }, + { SDLK_DOWN, "Arrow Down", "DownArrow" }, + { SDLK_RIGHT, "Arrow Right", "RightArrow" }, + { SDLK_LEFT, "Arrow Left", "LeftArrow" }, + { SDLK_INSERT, "Insert", "Ins" }, + { SDLK_HOME, "Home", 0 }, + { SDLK_END, "End", 0 }, + { SDLK_PAGEUP, "Page Up", "PgUp" }, + { SDLK_PAGEDOWN, "Page Down", "PgDn" }, + + { SDLK_F1, "F1", 0 }, + { SDLK_F2, "F2", 0 }, + { SDLK_F3, "F3", 0 }, + { SDLK_F4, "F4", 0 }, + { SDLK_F5, "F5", 0 }, + { SDLK_F6, "F6", 0 }, + { SDLK_F7, "F7", 0 }, + { SDLK_F8, "F8", 0 }, + { SDLK_F9, "F9", 0 }, + { SDLK_F10, "F10", 0 }, + { SDLK_F11, "F11", 0 }, + { SDLK_F12, "F12", 0 }, + { SDLK_F13, "F13", 0 }, + { SDLK_F14, "F14", 0 }, + { SDLK_F15, "F15", 0 }, + + { SDLK_NUMLOCK, "Num Lock", "NumLock" }, + { SDLK_CAPSLOCK, "Caps Lock", "CapsLock" }, + { SDLK_SCROLLOCK, "Scroll Lock", "ScrlLock" }, + { SDLK_RSHIFT, "Right Shift", "RightShift" }, + { SDLK_LSHIFT, "Left Shift", "LeftShift" }, + { SDLK_RCTRL, "Right Ctrl", "RightCtrl" }, + { SDLK_LCTRL, "Left Ctrl", "LeftCtrl" }, + { SDLK_RALT, "Right Alt", "RightAlt" }, + { SDLK_LALT, "Left Alt", "LeftAlt" }, + { SDLK_RMETA, "Right Meta", 0 }, // ? + { SDLK_LMETA, "Left Meta", 0 }, // ? + { SDLK_LSUPER, "Left Super", "LeftWin" }, /* "Windows" keys */ + { SDLK_RSUPER, "Right Super", "RightWin" }, + { SDLK_MODE, "Alt Gr", "AltGr" }, + { SDLK_COMPOSE, "Compose", 0 }, // ? + + { SDLK_HELP, "Help", 0 }, // ? + { SDLK_PRINT, "Print Screen", "PrtSc" }, + { SDLK_SYSREQ, "SysRq", 0 }, + { SDLK_BREAK, "Break", 0 }, + { SDLK_MENU, "Menu", 0 }, // ? + { SDLK_POWER, "Power", 0 }, // ? + { SDLK_EURO, "Euro", 0 }, + { SDLK_UNDO, "Undo", 0 }, // ? + { SDLK_LAST + SDL_BUTTON_LEFT, "Left Mouse Button", "MouseLeft" }, + { SDLK_LAST + SDL_BUTTON_RIGHT, "Right Mouse Button", "MouseRight" }, + { SDLK_LAST + SDL_BUTTON_MIDDLE, "Middle Mouse Button", "MouseMiddle" }, + { SDLK_LAST + SDL_BUTTON_WHEELUP, "Mouse Wheel Up", "WheelUp" }, + { SDLK_LAST + SDL_BUTTON_WHEELDOWN, "Mouse Wheel Down", "WheelDown" }, + { 0, 0, 0 }, +}; + +void initKeyNameMap() +{ + SKeycodeMapping* it = keycodeMapping; + while( it->keycode != 0 ) + { + keymap.insert( std::pair( CStr( it->keyname ).LowerCase(), it->keycode ) ); + if( it->altkeyname ) + keymap.insert( std::pair( CStr( it->altkeyname ).LowerCase(), it->keycode ) ); + it++; + }; +} + +int getKeyCode( CStr keyname ) +{ + std::map::iterator it; + it = keymap.find( keyname.LowerCase() ); + if( it != keymap.end() ) + return( it->second ); + return( 0 ); +} + +CStr getKeyName( int keycode ) +{ + SKeycodeMapping* it = keycodeMapping; + while( it->keycode != 0 ) + { + if( it->keycode == keycode ) + return( CStr( it->keyname ) ); + } + return( CStr( "Unknown" ) ); +} + +