From 8aae821e59e1d39f0f37a6c8667defb8c8e4db66 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Fri, 1 Oct 2021 14:46:55 +0100 Subject: [PATCH] [Shortcut Guide] Suppress Windows Menu appearing (#13553) * Get the new settings values * Suppress windows menu appearing * Send new settings telemetry * Address PR comments --- .../ShortcutGuide/ShortcutGuideSettings.h | 2 ++ .../ShortcutGuide/shortcut_guide.cpp | 26 +++++++++++++++++++ .../ShortcutGuide/shortcut_guide.h | 11 ++++++++ .../ShortcutGuide/ShortcutGuide/trace.cpp | 2 ++ 4 files changed, 41 insertions(+) diff --git a/src/modules/ShortcutGuide/ShortcutGuide/ShortcutGuideSettings.h b/src/modules/ShortcutGuide/ShortcutGuide/ShortcutGuideSettings.h index 224c19390b..0f6b131f25 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide/ShortcutGuideSettings.h +++ b/src/modules/ShortcutGuide/ShortcutGuide/ShortcutGuideSettings.h @@ -7,4 +7,6 @@ struct ShortcutGuideSettings int overlayOpacity = 90; std::wstring theme = L"system"; std::wstring disabledApps = L""; + bool shouldReactToPressedWinKey = false; + int windowsKeyPressTime = 900; }; diff --git a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp index 89d8618549..db46af81ef 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp +++ b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp @@ -221,6 +221,15 @@ void OverlayWindow::CloseWindow(HideWindowType type, int mainThreadId) if (this->winkey_popup) { + if (shouldReactToPressedWinKey.value) + { + // Send a dummy key to prevent Start Menu from activating + INPUT dummyEvent[1] = {}; + dummyEvent[0].type = INPUT_KEYBOARD; + dummyEvent[0].ki.wVk = 0xFF; + dummyEvent[0].ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(1, dummyEvent, sizeof(INPUT)); + } this->winkey_popup->SetWindowCloseType(ToWstring(type)); Logger::trace(L"Terminating process"); PostThreadMessage(mainThreadId, WM_QUIT, 0, 0); @@ -300,6 +309,7 @@ void OverlayWindow::init_settings() overlayOpacity.value = settings.overlayOpacity; theme.value = settings.theme; disabledApps.value = settings.disabledApps; + shouldReactToPressedWinKey.value = settings.shouldReactToPressedWinKey; update_disabled_apps(); } @@ -399,6 +409,22 @@ ShortcutGuideSettings OverlayWindow::GetSettings() noexcept { } + try + { + settings.shouldReactToPressedWinKey = properties.GetNamedObject(ShouldReactToPressedWinKey::name).GetNamedBoolean(L"value"); + } + catch (...) + { + } + + try + { + settings.windowsKeyPressTime = (int)properties.GetNamedObject(WindowsKeyPressTime::name).GetNamedNumber(L"value"); + } + catch (...) + { + } + try { settings.theme = (std::wstring)properties.GetNamedObject(Theme::name).GetNamedString(L"value"); diff --git a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h index d9288725d4..3fde8bf7a3 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h +++ b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h @@ -78,6 +78,17 @@ private: std::wstring value; } disabledApps; + struct ShouldReactToPressedWinKey + { + static inline PCWSTR name = L"use_legacy_press_win_key_behavior"; + bool value; + } shouldReactToPressedWinKey; + + struct WindowsKeyPressTime + { + static inline PCWSTR name = L"press_time"; + } windowsKeyPressTime; + struct OpenShortcut { static inline PCWSTR name = L"open_shortcutguide"; diff --git a/src/modules/ShortcutGuide/ShortcutGuide/trace.cpp b/src/modules/ShortcutGuide/ShortcutGuide/trace.cpp index d8cb68b18c..2b7e9a123c 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide/trace.cpp +++ b/src/modules/ShortcutGuide/ShortcutGuide/trace.cpp @@ -39,6 +39,8 @@ void Trace::SendSettings(ShortcutGuideSettings settings) noexcept TraceLoggingInt32(settings.overlayOpacity, "OverlayOpacity"), TraceLoggingWideString(settings.theme.c_str(), "Theme"), TraceLoggingWideString(settings.disabledApps.c_str(), "DisabledApps"), + TraceLoggingBoolean(settings.shouldReactToPressedWinKey, "ShouldReactToPressedWinKey"), + TraceLoggingInt32(settings.windowsKeyPressTime, "WindowsKeyPressTime"), ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"), TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));