14static SDL_Keycode getKeyFromOldOpenmsxName(std::string_view name)
36 std::string_view name;
39 static constexpr std::array unsortedMap = {
41 M{
"EXCLAIM", SDLK_EXCLAIM},
42 M{
"QUOTEDBL", SDLK_QUOTEDBL},
44 M{
"DOLLAR", SDLK_DOLLAR},
45 M{
"AMPERSAND", SDLK_AMPERSAND},
46 M{
"QUOTE", SDLK_QUOTE},
47 M{
"LEFTPAREN", SDLK_LEFTPAREN},
48 M{
"RIGHTPAREN", SDLK_RIGHTPAREN},
49 M{
"ASTERISK", SDLK_ASTERISK},
51 M{
"COMMA", SDLK_COMMA},
52 M{
"MINUS", SDLK_MINUS},
53 M{
"PERIOD", SDLK_PERIOD},
54 M{
"SLASH", SDLK_SLASH},
55 M{
"COLON", SDLK_COLON},
56 M{
"SEMICOLON", SDLK_SEMICOLON},
58 M{
"EQUALS", SDLK_EQUALS},
59 M{
"GREATER", SDLK_GREATER},
60 M{
"QUESTION", SDLK_QUESTION},
62 M{
"LEFTBRACKET", SDLK_LEFTBRACKET},
63 M{
"BACKSLASH", SDLK_BACKSLASH},
64 M{
"RIGHTBRACKET",SDLK_RIGHTBRACKET},
65 M{
"CARET", SDLK_CARET},
66 M{
"UNDERSCORE", SDLK_UNDERSCORE},
67 M{
"BACKQUOTE", SDLK_BACKQUOTE},
68 M{
"PRINT", SDLK_PRINTSCREEN},
69 M{
"SCROLLOCK", SDLK_SCROLLLOCK},
70 M{
"KP_DIVIDE", SDLK_KP_DIVIDE},
71 M{
"KP_MULTIPLY", SDLK_KP_MULTIPLY},
72 M{
"KP_MINUS", SDLK_KP_MINUS},
73 M{
"KP_PLUS", SDLK_KP_PLUS},
74 M{
"KP_ENTER", SDLK_KP_ENTER},
85 M{
"KP_PERIOD", SDLK_KP_PERIOD},
86 M{
"KP_EQUALS", SDLK_KP_EQUALS},
87 M{
"LCTRL", SDLK_LCTRL},
88 M{
"LSHIFT", SDLK_LSHIFT},
90 M{
"LSUPER", SDLK_LGUI},
91 M{
"RCTRL", SDLK_RCTRL},
92 M{
"RSHIFT", SDLK_RSHIFT},
94 M{
"RSUPER", SDLK_RGUI},
95 M{
"RMODE", SDLK_MODE},
97 static constexpr auto map = []{
98 auto result = unsortedMap;
111 auto result = SDL_GetKeyFromName(name.
c_str());
112 if (result == SDLK_UNKNOWN) {
114 result = getKeyFromOldOpenmsxName(name);
161 result.
sym.scancode = SDL_SCANCODE_UNKNOWN;
162 result.
sym.sym = SDLK_UNKNOWN;
163 result.
sym.mod = KMOD_NONE;
164 result.
sym.unused = 0;
167 while (!name.empty()) {
168 std::string_view part = [&] {
169 auto pos = name.find_first_of(
",+/");
170 if (pos == std::string_view::npos) {
172 return std::exchange(name, std::string_view{});
173 }
else if ((pos + 1) == name.size()) {
175 return std::exchange(name, std::string_view{});
177 if (name[pos + 1] ==
one_of(
',',
'+',
'/')) {
182 auto r = name.substr(0, pos);
183 name.remove_prefix(pos + 1);
189 if (cmp(part,
"SHIFT")) {
190 result.
sym.mod |= KMOD_SHIFT;
191 }
else if (cmp(part,
"CTRL")) {
192 result.
sym.mod |= KMOD_CTRL;
193 }
else if (cmp(part,
"ALT")) {
194 result.
sym.mod |= KMOD_ALT;
195 }
else if (cmp(part,
"GUI") ||
197 result.
sym.mod |= KMOD_GUI;
198 }
else if (cmp(part,
"MODE")) {
199 result.
sym.mod |= KMOD_MODE;
201 }
else if (cmp(part,
"PRESS")) {
203 }
else if (cmp(part,
"RELEASE")) {
207 if (result.
sym.sym != SDLK_UNKNOWN) {
212 if (result.
sym.sym == SDLK_UNKNOWN) {
217 if (result.
sym.sym == SDLK_UNKNOWN) {
225 std::string result = SDL_GetKeyName(code);
226 if (result.empty()) result =
"unknown";
233 if (
sym.mod & KMOD_CTRL) {
236 if (
sym.mod & KMOD_SHIFT) {
239 if (
sym.mod & KMOD_ALT) {
242 if (
sym.mod & KMOD_GUI) {
245 if (
sym.mod & KMOD_MODE) {
249 result +=
",RELEASE";
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr const char * c_str() const
This file implemented 3 utility functions:
constexpr void sort(RandomAccessRange &&range)
auto * binary_find(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
static SDL_Keycode keycodeFromString(zstring_view name)
static std::optional< SDLKey > fromString(std::string_view name)
std::string toString() const