From b1131263cf6d7338810557cafe6378a9d13a1e81 Mon Sep 17 00:00:00 2001 From: PankajBhojwani Date: Tue, 24 Aug 2021 07:07:45 -0700 Subject: [PATCH] Fix alt+space opening system menu and sending keys to terminal (#10988) If both of the following are true 1. alt+space is not explicitly unbound 2. alt+space is not bound to a command Then the window procedure will handle the alt+space to open up the context menu. In this case, we need to make sure we don't send the keys to terminal. Closes #10935 --- src/cascadia/TerminalControl/TermControl.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index e36fadd6a..3e3d7414e 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -900,6 +900,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation return; } + if (vkey == VK_SPACE && modifiers.IsAltPressed()) + { + if (const auto bindings = _settings.KeyBindings()) + { + if (!bindings.IsKeyChordExplicitlyUnbound({ modifiers.IsCtrlPressed(), modifiers.IsAltPressed(), modifiers.IsShiftPressed(), modifiers.IsWinPressed(), vkey, scanCode })) + { + // If we get here, it means that + // 1. we do not have a command bound to alt+space + // 2. alt+space was not explicitly unbound + // That means that XAML handled the alt+space to open up the context menu, and + // so we don't want to send anything to the terminal + // TODO GH#11018: Add a new "openSystemMenu" keybinding + e.Handled(true); + return; + } + } + } + if (_TrySendKeyEvent(vkey, scanCode, modifiers, keyDown)) { e.Handled(true);