From 72483a5deaec7c2489c2087ef8f07feccae2aedf Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Tue, 11 Jul 2023 16:49:14 -0400 Subject: [PATCH] macos: Add special mapping for insert key --- src/qt/cocoa_keyboard.hpp | 6 ++++++ src/qt/qt_mainwindow.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/qt/cocoa_keyboard.hpp b/src/qt/cocoa_keyboard.hpp index eaf0cdfe0..da3161bb2 100644 --- a/src/qt/cocoa_keyboard.hpp +++ b/src/qt/cocoa_keyboard.hpp @@ -127,3 +127,9 @@ static std::array cocoa_keycodes = { /* key names in parentheses 0x150, /* DownArrow */ 0x148, /* UpArrow */ }; + +// https://developer.apple.com/documentation/appkit/nseventmodifierflags/ +qint32 NSEventModifierFlagCommand = 1 << 20; + +qint32 nvk_Delete = 0x75; +qint32 nvk_Insert = 0x72; \ No newline at end of file diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 7d37c0c84..30276922f 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -1092,6 +1092,11 @@ MainWindow::processMacKeyboardInput(bool down, const QKeyEvent *event) if (mac_iso_swap) nvk = (nvk == 0x0a) ? 0x32 : 0x0a; } + // Special case for command + forward delete to send insert. + if ((event->nativeModifiers() & NSEventModifierFlagCommand) && + ((event->nativeVirtualKey() == nvk_Delete) || event->key() == Qt::Key_Delete)) { + nvk = nvk_Insert; // Qt::Key_Help according to event->key() + } processKeyboardInput(down, nvk); }