From 0d37ea42f911c2c7f838d511d97cceb152215eb5 Mon Sep 17 00:00:00 2001 From: Joe Wagner Date: Wed, 18 Sep 2024 08:44:59 -0700 Subject: [PATCH 1/3] Update QtKeyCodes.cpp This addresses an issue present in EQOA where SHIFT only worked on alpha characters. SHIFT now is detected and works to produce symbols as well. --- pcsx2-qt/QtKeyCodes.cpp | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) 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)); } From f8f8049fd321732d92e7bcfecf895970366b1017 Mon Sep 17 00:00:00 2001 From: Joe Wagner Date: Wed, 18 Sep 2024 09:25:33 -0700 Subject: [PATCH 2/3] fix for formatting --- pcsx2-qt/QtKeyCodes.cpp | 88 ++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/pcsx2-qt/QtKeyCodes.cpp b/pcsx2-qt/QtKeyCodes.cpp index 7d8ac54b3f..81caba442d 100644 --- a/pcsx2-qt/QtKeyCodes.cpp +++ b/pcsx2-qt/QtKeyCodes.cpp @@ -13,29 +13,51 @@ #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 +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 @@ -542,16 +564,18 @@ const char* InputManager::ConvertHostKeyboardCodeToIcon(u32 code) return nullptr; } -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(); +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 - } + if (keycode != 0) + { + key = keycode; // Override key if mapped + } - Qt::KeyboardModifiers modifiers = ev->modifiers(); + Qt::KeyboardModifiers modifiers = ev->modifiers(); #ifdef __APPLE__ // On macOS, Qt applies the Keypad modifier regardless of whether the arrow keys, or numpad was pressed. @@ -567,5 +591,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)); } From 6f7416425a4b9eb11995918b41e4f8c844b80e5c Mon Sep 17 00:00:00 2001 From: Joe Wagner Date: Wed, 18 Sep 2024 19:27:07 -0700 Subject: [PATCH 3/3] change uint8_t to u8 for consistency --- pcsx2-qt/QtKeyCodes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcsx2-qt/QtKeyCodes.cpp b/pcsx2-qt/QtKeyCodes.cpp index 81caba442d..aec29c9862 100644 --- a/pcsx2-qt/QtKeyCodes.cpp +++ b/pcsx2-qt/QtKeyCodes.cpp @@ -13,7 +13,7 @@ #include -uint8_t map_text_to_keycode(const QString& text) +u8 map_text_to_keycode(const QString& text) { if (text == "!") return Qt::Key_1; @@ -567,7 +567,7 @@ const char* InputManager::ConvertHostKeyboardCodeToIcon(u32 code) u32 QtUtils::KeyEventToCode(const QKeyEvent* ev) { QString text = ev->text(); - uint8_t keycode = map_text_to_keycode(text); // Map special text symbols to keycodes + u8 keycode = map_text_to_keycode(text); // Map special text symbols to keycodes int key = ev->key(); if (keycode != 0)