diff --git a/pcsx2-qt/QtKeyCodes.cpp b/pcsx2-qt/QtKeyCodes.cpp index d299107b2f..7d8ac54b3f 100644 --- a/pcsx2-qt/QtKeyCodes.cpp +++ b/pcsx2-qt/QtKeyCodes.cpp @@ -13,6 +13,31 @@ #include +uint8_t map_text_to_keycode(const QString& text) { + if (text == "!") return Qt::Key_1; + if (text == "@") return Qt::Key_2; + if (text == "#") return Qt::Key_3; + if (text == "$") return Qt::Key_4; + if (text == "%") return Qt::Key_5; + if (text == "^") return Qt::Key_6; + if (text == "&") return Qt::Key_7; + if (text == "*") return Qt::Key_8; + if (text == "(") return Qt::Key_9; + if (text == ")") return Qt::Key_0; + if (text == "_") return Qt::Key_Minus; + if (text == "+") return Qt::Key_Equal; + if (text == "?") return Qt::Key_Slash; + if (text == ":") return Qt::Key_Semicolon; + if (text == "\"") return Qt::Key_Apostrophe; + if (text == "~") return Qt::Key_QuoteLeft; + if (text == "<") return Qt::Key_Comma; + if (text == ">") return Qt::Key_Period; + if (text == "|") return Qt::Key_Backslash; + if (text == "{") return Qt::Key_BracketLeft; + if (text == "}") return Qt::Key_BracketRight; + return 0; // No remapping +} + struct KeyCodeName { int code; @@ -517,10 +542,16 @@ const char* InputManager::ConvertHostKeyboardCodeToIcon(u32 code) return nullptr; } -u32 QtUtils::KeyEventToCode(const QKeyEvent* ev) -{ - int key = ev->key(); - Qt::KeyboardModifiers modifiers = ev->modifiers(); +u32 QtUtils::KeyEventToCode(const QKeyEvent* ev) { + QString text = ev->text(); + uint8_t keycode = map_text_to_keycode(text); // Map special text symbols to keycodes + int key = ev->key(); + + if (keycode != 0) { + key = keycode; // Override key if mapped + } + + Qt::KeyboardModifiers modifiers = ev->modifiers(); #ifdef __APPLE__ // On macOS, Qt applies the Keypad modifier regardless of whether the arrow keys, or numpad was pressed. @@ -536,5 +567,5 @@ u32 QtUtils::KeyEventToCode(const QKeyEvent* ev) } #endif - return static_cast(key) | (static_cast(modifiers) & static_cast(Qt::KeypadModifier)); + return static_cast(key) | (static_cast(modifiers) & static_cast(Qt::KeypadModifier)); }