Skip to content

Instantly share code, notes, and snippets.

@qookei
Last active December 10, 2019 15:37
Show Gist options
  • Save qookei/b778aff38c974f449f2dc03a74ab5c2e to your computer and use it in GitHub Desktop.
Save qookei/b778aff38c974f449f2dc03a74ab5c2e to your computer and use it in GitHub Desktop.
Key name to SFML constant
sf::Keyboard::Key translate_key_name(const std::string &name) {
if (name == "a") return sf::Keyboard::A;
if (name == "b") return sf::Keyboard::B;
if (name == "c") return sf::Keyboard::C;
if (name == "d") return sf::Keyboard::D;
if (name == "e") return sf::Keyboard::E;
if (name == "f") return sf::Keyboard::F;
if (name == "g") return sf::Keyboard::G;
if (name == "h") return sf::Keyboard::H;
if (name == "i") return sf::Keyboard::I;
if (name == "j") return sf::Keyboard::J;
if (name == "k") return sf::Keyboard::K;
if (name == "l") return sf::Keyboard::L;
if (name == "m") return sf::Keyboard::M;
if (name == "n") return sf::Keyboard::N;
if (name == "o") return sf::Keyboard::O;
if (name == "p") return sf::Keyboard::P;
if (name == "q") return sf::Keyboard::Q;
if (name == "r") return sf::Keyboard::R;
if (name == "s") return sf::Keyboard::S;
if (name == "t") return sf::Keyboard::T;
if (name == "u") return sf::Keyboard::U;
if (name == "v") return sf::Keyboard::V;
if (name == "w") return sf::Keyboard::W;
if (name == "x") return sf::Keyboard::X;
if (name == "y") return sf::Keyboard::Y;
if (name == "z") return sf::Keyboard::Z;
if (name == "num0") return sf::Keyboard::Num0;
if (name == "num1") return sf::Keyboard::Num1;
if (name == "num2") return sf::Keyboard::Num2;
if (name == "num3") return sf::Keyboard::Num3;
if (name == "num4") return sf::Keyboard::Num4;
if (name == "num5") return sf::Keyboard::Num5;
if (name == "num6") return sf::Keyboard::Num6;
if (name == "num7") return sf::Keyboard::Num7;
if (name == "num8") return sf::Keyboard::Num8;
if (name == "num9") return sf::Keyboard::Num9;
if (name == "escape") return sf::Keyboard::Escape;
if (name == "lcontrol") return sf::Keyboard::LControl;
if (name == "lshift") return sf::Keyboard::LShift;
if (name == "lalt") return sf::Keyboard::LAlt;
if (name == "lsystem") return sf::Keyboard::LSystem;
if (name == "rcontrol") return sf::Keyboard::RControl;
if (name == "rshift") return sf::Keyboard::RShift;
if (name == "ralt") return sf::Keyboard::RAlt;
if (name == "rsystem") return sf::Keyboard::RSystem;
if (name == "menu") return sf::Keyboard::Menu;
if (name == "lbracket") return sf::Keyboard::LBracket;
if (name == "rbracket") return sf::Keyboard::RBracket;
if (name == "semicolon") return sf::Keyboard::Semicolon;
if (name == "comma") return sf::Keyboard::Comma;
if (name == "period") return sf::Keyboard::Period;
if (name == "quote") return sf::Keyboard::Quote;
if (name == "slash") return sf::Keyboard::Slash;
if (name == "backslash") return sf::Keyboard::Backslash;
if (name == "tilde") return sf::Keyboard::Tilde;
if (name == "equal") return sf::Keyboard::Equal;
if (name == "hyphen") return sf::Keyboard::Hyphen;
if (name == "space") return sf::Keyboard::Space;
if (name == "enter") return sf::Keyboard::Enter;
if (name == "backspace") return sf::Keyboard::Backspace;
if (name == "tab") return sf::Keyboard::Tab;
if (name == "pageup") return sf::Keyboard::PageUp;
if (name == "pagedown") return sf::Keyboard::PageDown;
if (name == "end") return sf::Keyboard::End;
if (name == "home") return sf::Keyboard::Home;
if (name == "insert") return sf::Keyboard::Insert;
if (name == "delete") return sf::Keyboard::Delete;
if (name == "add") return sf::Keyboard::Add;
if (name == "subtract") return sf::Keyboard::Subtract;
if (name == "multiply") return sf::Keyboard::Multiply;
if (name == "divide") return sf::Keyboard::Divide;
if (name == "left") return sf::Keyboard::Left;
if (name == "right") return sf::Keyboard::Right;
if (name == "up") return sf::Keyboard::Up;
if (name == "down") return sf::Keyboard::Down;
if (name == "numpad0") return sf::Keyboard::Numpad0;
if (name == "numpad1") return sf::Keyboard::Numpad1;
if (name == "numpad2") return sf::Keyboard::Numpad2;
if (name == "numpad3") return sf::Keyboard::Numpad3;
if (name == "numpad4") return sf::Keyboard::Numpad4;
if (name == "numpad5") return sf::Keyboard::Numpad5;
if (name == "numpad6") return sf::Keyboard::Numpad6;
if (name == "numpad7") return sf::Keyboard::Numpad7;
if (name == "numpad8") return sf::Keyboard::Numpad8;
if (name == "numpad9") return sf::Keyboard::Numpad9;
if (name == "f1") return sf::Keyboard::F1;
if (name == "f2") return sf::Keyboard::F2;
if (name == "f3") return sf::Keyboard::F3;
if (name == "f4") return sf::Keyboard::F4;
if (name == "f5") return sf::Keyboard::F5;
if (name == "f6") return sf::Keyboard::F6;
if (name == "f7") return sf::Keyboard::F7;
if (name == "f8") return sf::Keyboard::F8;
if (name == "f9") return sf::Keyboard::F9;
if (name == "f10") return sf::Keyboard::F10;
if (name == "f11") return sf::Keyboard::F11;
if (name == "f12") return sf::Keyboard::F12;
if (name == "f13") return sf::Keyboard::F13;
if (name == "f14") return sf::Keyboard::F14;
if (name == "f15") return sf::Keyboard::F15;
if (name == "pause") return sf::Keyboard::Pause;
return sf::Keyboard::Unknown;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment