diff --git a/src/Calculator/Common/KeyboardShortcuManager.cs b/src/Calculator/Common/KeyboardShortcuManager.cs index 1a9aa991..78c0ab19 100644 --- a/src/Calculator/Common/KeyboardShortcuManager.cs +++ b/src/Calculator/Common/KeyboardShortcuManager.cs @@ -249,6 +249,7 @@ namespace CalculatorApp var coreWindow = Window.Current.CoreWindow; coreWindow.CharacterReceived += OnCharacterReceivedHandler; coreWindow.KeyDown += OnKeyDownHandler; + coreWindow.KeyUp += OnKeyUpHandler; coreWindow.Dispatcher.AcceleratorKeyActivated += OnAcceleratorKeyActivated; KeyboardShortcutManager.RegisterNewAppViewId(); } @@ -630,6 +631,7 @@ namespace CalculatorApp private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterReceivedEventArgs args) { int viewId = Utilities.GetWindowId(); + bool hit = s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts); if (!hit || currentHonorShortcuts) @@ -644,6 +646,7 @@ namespace CalculatorApp private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args) { + s_keyHandlerCount++; if (args.Handled) { return; @@ -714,6 +717,29 @@ namespace CalculatorApp } } + private static void OnKeyUpHandler(CoreWindow sender, KeyEventArgs args) + { + s_keyHandlerCount--; + if (s_keyHandlerCount == 0 && s_deferredEnableShortcut) + { + KeyboardShortcutManager.DisableShortcuts(false);//shortcuts enabled + s_deferredEnableShortcut = false; + } + + } + + public static void TryEnableShortcut() + { + if (s_keyHandlerCount > 0) + { + s_deferredEnableShortcut = true; + } + else + { + KeyboardShortcutManager.DisableShortcuts(true); + } + } + private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args) { if (args.KeyStatus.IsKeyReleased) @@ -831,6 +857,10 @@ namespace CalculatorApp //private static Concurrency.reader_writer_lock s_keyboardShortcutMapLock; private static readonly object s_keyboardShortcutMapLockMutex = new object(); + + + private static int s_keyHandlerCount; + private static bool s_deferredEnableShortcut; } } } diff --git a/src/Calculator/Views/MainPage.xaml.cs b/src/Calculator/Views/MainPage.xaml.cs index d8b5f249..d3656fd3 100644 --- a/src/Calculator/Views/MainPage.xaml.cs +++ b/src/Calculator/Views/MainPage.xaml.cs @@ -201,7 +201,7 @@ namespace CalculatorApp ViewMode newValue = m_model.Mode; ViewMode previousMode = m_model.PreviousMode; - KeyboardShortcutManager.DisableShortcuts(false); + KeyboardShortcutManager.TryEnableShortcut(); if (newValue == ViewMode.Standard) {