diff --git a/irr/include/IrrlichtDevice.h b/irr/include/IrrlichtDevice.h index 717989978..28e11bef7 100644 --- a/irr/include/IrrlichtDevice.h +++ b/irr/include/IrrlichtDevice.h @@ -349,7 +349,11 @@ public: //! Get the scancode of the corresponding keycode. virtual u32 getScancodeFromKey(const KeyCode &key) const { - return key.index() == 0 ? std::get(key) : KEY_KEY_CODES_COUNT + std::get(key); + if (const auto *keycode = std::get_if(&key)) + // treat KEY_UNKNOWN and KEY_KEY_CODES_COUNT as the same and return 0. + return KeyCode::isValid(*keycode) ? *keycode : 0; + const auto keychar = std::get(key); + return keychar == 0 ? 0 : KEY_KEY_CODES_COUNT + keychar; } //! Get the keycode of the corresponding scancode. diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index 035272460..5b7b4a93e 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -223,10 +223,9 @@ int CIrrDeviceSDL::findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtK u32 CIrrDeviceSDL::getScancodeFromKey(const KeyCode &key) const { u32 keynum = 0; - if (key.index() == 0) { - auto keycode = std::get(key); + if (const auto *keycode = std::get_if(&key)) { for (const auto &entry: KeyMap) { - if (entry.second == keycode) { + if (entry.second == *keycode) { keynum = entry.first; break; } diff --git a/src/client/keycode.cpp b/src/client/keycode.cpp index 76f781595..29949bbb8 100644 --- a/src/client/keycode.cpp +++ b/src/client/keycode.cpp @@ -275,7 +275,9 @@ static const table_key &lookup_keykey(irr::EKEY_CODE key) static const table_key &lookup_scancode(const u32 scancode) { auto key = RenderingEngine::get_raw_device()->getKeyFromScancode(scancode); - return key.index() == 0 ? lookup_keykey(std::get(key)) : lookup_keychar(std::get(key)); + return std::holds_alternative(key) ? + lookup_keykey(std::get(key)) : + lookup_keychar(std::get(key)); } KeyPress::KeyPress(std::string_view name)