From a3f69300725c84f71096bf0e13d01ea6a4919425 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 4 Mar 2024 23:28:49 +1000 Subject: [PATCH] Qt: Fix default arrow key binding on MacOS --- src/duckstation-qt/qtkeycodes.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/duckstation-qt/qtkeycodes.cpp b/src/duckstation-qt/qtkeycodes.cpp index cdcf0b161..7c09bdc80 100644 --- a/src/duckstation-qt/qtkeycodes.cpp +++ b/src/duckstation-qt/qtkeycodes.cpp @@ -517,5 +517,22 @@ const char* InputManager::ConvertHostKeyboardCodeToIcon(u32 code) u32 QtUtils::KeyEventToCode(const QKeyEvent* ev) { - return static_cast(ev->key()) | (static_cast(ev->modifiers()) & static_cast(Qt::KeypadModifier)); + int key = ev->key(); + Qt::KeyboardModifiers modifiers = ev->modifiers(); + +#ifdef __APPLE__ + // On macOS, Qt applies the Keypad modifier regardless of whether the arrow keys, or numpad was pressed. + // The only way to differentiate between the keypad and the arrow keys is by the text. + // Hopefully some keyboard layouts don't change the numpad positioning... + if (modifiers & Qt::KeypadModifier && key >= Qt::Key_Insert && key <= Qt::Key_PageDown) + { + if (ev->text().isEmpty()) + { + // Drop the modifier, because it's probably not actually a numpad push. + modifiers &= ~Qt::KeypadModifier; + } + } +#endif + + return static_cast(key) | (static_cast(modifiers) & static_cast(Qt::KeypadModifier)); }