From 91d43ea4b50ef1e7df810ab1f14c49e044570734 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 26 Jul 2023 12:00:10 +0400 Subject: [PATCH] Provide (almost) correct modifiers in DirectManipulation. --- ui/platform/win/ui_window_win.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ui/platform/win/ui_window_win.cpp b/ui/platform/win/ui_window_win.cpp index e434525..7918bf4 100644 --- a/ui/platform/win/ui_window_win.cpp +++ b/ui/platform/win/ui_window_win.cpp @@ -144,6 +144,28 @@ void FixAeroSnap(HWND handle) { return result; } +[[nodiscard]] Qt::KeyboardModifiers LookupModifiers() { + const auto check = [](int key) { + return (GetKeyState(key) & 0x8000) != 0; + }; + + auto result = Qt::KeyboardModifiers(); + if (check(VK_SHIFT)) { + result |= Qt::ShiftModifier; + } + // NB AltGr key (i.e., VK_RMENU on some keyboard layout) is not handled. + if (check(VK_RMENU) || check(VK_MENU)) { + result |= Qt::AltModifier; + } + if (check(VK_CONTROL)) { + result |= Qt::ControlModifier; + } + if (check(VK_LWIN) || check(VK_RWIN)) { + result |= Qt::MetaModifier; + } + return result; +} + } // namespace class WindowHelper::NativeFilter final : public QAbstractNativeEventFilter { @@ -431,7 +453,7 @@ void WindowHelper::handleDirectManipulationEvent( QPointF(global.x, global.y), event.delta, event.delta, - QGuiApplication::keyboardModifiers(), + LookupModifiers(), phase, Qt::MouseEventSynthesizedBySystem); }