From 6430551167b790c8142d11b3d89a871d0f1c558a Mon Sep 17 00:00:00 2001 From: jbaylon3 <89996520+jbaylon3@users.noreply.github.com> Date: Mon, 13 Jun 2022 19:03:40 -0700 Subject: [PATCH] Fix the captured access key in the result box * Fix issue #1782 * Fixed issue 1782 * Fix issue 1782 * Fix issue #1782 * Fix Issue #1782 Co-authored-by: Jesus Baylon --- .../Common/KeyboardShortcutManager.cs | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Calculator/Common/KeyboardShortcutManager.cs b/src/Calculator/Common/KeyboardShortcutManager.cs index 1a9aa99..dfcccf1 100644 --- a/src/Calculator/Common/KeyboardShortcutManager.cs +++ b/src/Calculator/Common/KeyboardShortcutManager.cs @@ -249,6 +249,7 @@ internal static void Initialize() var coreWindow = Window.Current.CoreWindow; coreWindow.CharacterReceived += OnCharacterReceivedHandler; coreWindow.KeyDown += OnKeyDownHandler; + coreWindow.KeyUp += OnKeyUpHandler; coreWindow.Dispatcher.AcceleratorKeyActivated += OnAcceleratorKeyActivated; KeyboardShortcutManager.RegisterNewAppViewId(); } @@ -322,14 +323,20 @@ public static void HonorShortcuts(bool allow) public static void DisableShortcuts(bool disable) { - int viewId = Utilities.GetWindowId(); - - if (s_fDisableShortcuts.ContainsKey(viewId)) + //deferredEnableShortcut is being used to prevent the mode change from happening before the user input has processed + if (s_keyHandlerCount > 0 && !disable) { - s_fDisableShortcuts[viewId] = disable; + s_deferredEnableShortcut = true; + } + else + { + int viewId = Utilities.GetWindowId(); + if (s_fDisableShortcuts.ContainsKey(viewId)) + { + s_fDisableShortcuts[viewId] = disable; + } + HonorShortcuts(!disable); } - - HonorShortcuts(!disable); } public static void UpdateDropDownState(bool isOpen) @@ -644,6 +651,8 @@ private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterRecei private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args) { + s_keyHandlerCount++; + if (args.Handled) { return; @@ -714,6 +723,16 @@ private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args) } } + private static void OnKeyUpHandler(CoreWindow sender, KeyEventArgs args) + { + s_keyHandlerCount--; + if (s_keyHandlerCount == 0 && s_deferredEnableShortcut) + { + DisableShortcuts(false); + s_deferredEnableShortcut = false; + } + } + private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args) { if (args.KeyStatus.IsKeyReleased) @@ -831,6 +850,9 @@ private static void Insert(SortedDictionary> de //private static Concurrency.reader_writer_lock s_keyboardShortcutMapLock; private static readonly object s_keyboardShortcutMapLockMutex = new object(); + + private static int s_keyHandlerCount = 0; + private static bool s_deferredEnableShortcut = false; } } }