Changeset View
Changeset View
Standalone View
Standalone View
source/ps/KeyName.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | static const SKeycodeMapping keycodeMapping[] = | ||||
{ SDLK_F15, "F15", 0 }, | { SDLK_F15, "F15", 0 }, | ||||
{ SDLK_NUMLOCKCLEAR, "Num Lock", "NumLock" }, | { SDLK_NUMLOCKCLEAR, "Num Lock", "NumLock" }, | ||||
{ SDLK_CAPSLOCK, "Caps Lock", "CapsLock" }, | { SDLK_CAPSLOCK, "Caps Lock", "CapsLock" }, | ||||
{ SDLK_SCROLLLOCK, "Scroll Lock", "ScrlLock" }, | { SDLK_SCROLLLOCK, "Scroll Lock", "ScrlLock" }, | ||||
{ SDLK_RSHIFT, "Right Shift", "RightShift" }, | { SDLK_RSHIFT, "Shift", "Right Shift" }, | ||||
{ SDLK_LSHIFT, "Left Shift", "LeftShift" }, | { SDLK_LSHIFT, "Shift", "Left Shift" }, | ||||
{ SDLK_RCTRL, "Right Ctrl", "RightCtrl" }, | { SDLK_RCTRL, "Ctrl", "Right Ctrl" }, | ||||
{ SDLK_LCTRL, "Left Ctrl", "LeftCtrl" }, | { SDLK_LCTRL, "Ctrl", "Left Ctrl" }, | ||||
{ SDLK_RALT, "Right Alt", "RightAlt" }, | { SDLK_RALT, "Alt", "Right Alt" }, | ||||
{ SDLK_LALT, "Left Alt", "LeftAlt" }, | { SDLK_LALT, "Alt", "Left Alt" }, | ||||
{ SDLK_LGUI, "Left Super", "LeftWin" }, /* "Windows" keys */ | { SDLK_LGUI, "Super", "Left Super" }, /* "Windows" keys */ | ||||
{ SDLK_RGUI, "Right Super", "RightWin" }, | { SDLK_RGUI, "Super", "Right Super" }, | ||||
Stan: Do we still the comment ? | |||||
{ SDLK_MODE, "Alt Gr", "AltGr" }, | { SDLK_MODE, "Alt Gr", "AltGr" }, | ||||
{ SDLK_HELP, "Help", 0 }, // ? | { SDLK_HELP, "Help", 0 }, // ? | ||||
{ SDLK_PRINTSCREEN, "Print Screen", "PrtSc" }, | { SDLK_PRINTSCREEN, "Print Screen", "PrtSc" }, | ||||
{ SDLK_SYSREQ, "SysRq", 0 }, | { SDLK_SYSREQ, "SysRq", 0 }, | ||||
Show All 14 Lines | static const SKeycodeMapping keycodeMapping[] = | ||||
{ UNIFIED_CTRL, "Ctrl", "AnyCtrl" }, | { UNIFIED_CTRL, "Ctrl", "AnyCtrl" }, | ||||
{ UNIFIED_ALT, "Alt", "AnyAlt" }, | { UNIFIED_ALT, "Alt", "AnyAlt" }, | ||||
{ UNIFIED_SUPER, "Super", "AnyWindows" }, | { UNIFIED_SUPER, "Super", "AnyWindows" }, | ||||
{ 0, 0, 0 }, | { 0, 0, 0 }, | ||||
}; | }; | ||||
void InitKeyNameMap() | void InitKeyNameMap() | ||||
{ | { | ||||
keymap.clear(); | |||||
for (const SKeycodeMapping* it = keycodeMapping; it->keycode != 0; ++it) | for (const SKeycodeMapping* it = keycodeMapping; it->keycode != 0; ++it) | ||||
{ | { | ||||
keymap.insert(std::pair<CStr,int>(CStr(it->keyname).LowerCase(), it->keycode)); | keymap.insert(std::pair<CStr,int>(CStr(it->keyname).LowerCase(), it->keycode)); | ||||
if(it->altkeyname) | if(it->altkeyname) | ||||
keymap.insert(std::pair<CStr,int>(CStr(it->altkeyname).LowerCase(), it->keycode)); | keymap.insert(std::pair<CStr,int>(CStr(it->altkeyname).LowerCase(), it->keycode)); | ||||
} | } | ||||
// Extra mouse buttons. | // Extra mouse buttons. | ||||
for (int i = 1; i < 256; ++i) // There is no mouse 0 | for (int i = 1; i < 256; ++i) // There is no mouse 0 | ||||
{ | { | ||||
keymap.insert(std::pair<CStr,int>("mousebutton" + CStr::FromInt(i), MOUSE_BASE + i)); | keymap.insert(std::pair<CStr,int>("mousebutton" + CStr::FromInt(i), MOUSE_BASE + i)); | ||||
keymap.insert(std::pair<CStr,int>("mousen" + CStr::FromInt(i), MOUSE_BASE + i)); | keymap.insert(std::pair<CStr,int>("mousen" + CStr::FromInt(i), MOUSE_BASE + i)); | ||||
} | } | ||||
} | } | ||||
int FindKeyCode(const CStr& keyname) | int FindKeyCode(const CStr& keyname) | ||||
{ | { | ||||
std::map<CStr,int>::iterator it; | std::map<CStr,int>::iterator it; | ||||
it = keymap.find(keyname.LowerCase()); | it = keymap.find(keyname.LowerCase()); | ||||
if (it != keymap.end()) | if (it != keymap.end()) | ||||
return it->second; | return it->second; | ||||
// Fallback to SDL. | |||||
SDL_Keycode keycode = SDL_GetKeyFromName(keyname.LowerCase().c_str()); | |||||
if (keycode != SDLK_UNKNOWN) | |||||
return keycode; | |||||
return 0; | return 0; | ||||
} | } | ||||
CStr FindKeyName(int keycode) | CStr FindKeyName(int keycode) | ||||
{ | { | ||||
for (const SKeycodeMapping* it = keycodeMapping; it->keycode != 0; ++it) | for (const SKeycodeMapping* it = keycodeMapping; it->keycode != 0; ++it) | ||||
if (it->keycode == keycode) | if (it->keycode == keycode) | ||||
return CStr(it->keyname); | return CStr(it->keyname); | ||||
// Fallback to SDL. | |||||
CStr name(SDL_GetKeyName(keycode)); | |||||
if (name != "") | |||||
return name; | |||||
return CStr("Unknown"); | return CStr("Unknown"); | ||||
} | } | ||||
Wildfire Games · Phabricator
Do we still the comment ?