diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index 20e41a527..035272460 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -242,7 +242,8 @@ KeyCode CIrrDeviceSDL::getKeyFromScancode(const u32 scancode) const auto keycode = SDL_GetKeyFromScancode((SDL_Scancode)scancode); const auto &keyentry = KeyMap.find(keycode); auto irrcode = keyentry != KeyMap.end() ? keyentry->second : KEY_UNKNOWN; - return KeyCode(irrcode, keycode); + auto keychar = findCharToPassToIrrlicht(keycode, irrcode, false); + return KeyCode(irrcode, keychar); } void CIrrDeviceSDL::resetReceiveTextInputEvents() diff --git a/src/client/keycode.cpp b/src/client/keycode.cpp index 927486b05..95739a845 100644 --- a/src/client/keycode.cpp +++ b/src/client/keycode.cpp @@ -284,6 +284,8 @@ static const table_key &lookup_scancode(const u32 scancode) KeyPress::KeyPress(const std::string_view &name) { + if (loadFromScancode(name)) + return; const auto &key = lookup_keyname(name); KeyCode keycode(key.Key, key.Char); scancode = RenderingEngine::get_raw_device()->getScancodeFromKey(keycode); @@ -291,12 +293,27 @@ KeyPress::KeyPress(const std::string_view &name) std::string KeyPress::sym() const { - return lookup_scancode(scancode).Name; + const auto &name = lookup_scancode(scancode).Name; + if (!name.empty() || scancode == 0) + return name; + return formatScancode(); } std::string KeyPress::name() const { - return lookup_scancode(scancode).LangName; + const auto &name = lookup_scancode(scancode).LangName; + auto table_key = lookup_scancode(scancode); + if (!name.empty() || scancode == 0) + return name; + return formatScancode(); +} + +bool KeyPress::loadFromScancode(const std::string_view &name) +{ + if (name.size() < 2 || name[0] != '<') + return false; + scancode = strtoul(name.data()+1, NULL, 10); + return scancode != 0; } std::unordered_map KeyPress::specialKeyCache; diff --git a/src/client/keycode.h b/src/client/keycode.h index fee9e5ddd..1e93d14ee 100644 --- a/src/client/keycode.h +++ b/src/client/keycode.h @@ -35,6 +35,13 @@ public: static const KeyPress &getSpecialKey(const std::string &name); private: + bool loadFromScancode(const std::string_view &name); + + inline std::string formatScancode() const + { + return "<" + std::to_string(scancode) + ">"; + } + u32 scancode = 0; static std::unordered_map specialKeyCache;