mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 06:13:14 -07:00
Fix issue #1782
This commit is contained in:
parent
f79a50d4e9
commit
999daf1fc0
2 changed files with 31 additions and 1 deletions
|
@ -249,6 +249,7 @@ namespace CalculatorApp
|
||||||
var coreWindow = Window.Current.CoreWindow;
|
var coreWindow = Window.Current.CoreWindow;
|
||||||
coreWindow.CharacterReceived += OnCharacterReceivedHandler;
|
coreWindow.CharacterReceived += OnCharacterReceivedHandler;
|
||||||
coreWindow.KeyDown += OnKeyDownHandler;
|
coreWindow.KeyDown += OnKeyDownHandler;
|
||||||
|
coreWindow.KeyUp += OnKeyUpHandler;
|
||||||
coreWindow.Dispatcher.AcceleratorKeyActivated += OnAcceleratorKeyActivated;
|
coreWindow.Dispatcher.AcceleratorKeyActivated += OnAcceleratorKeyActivated;
|
||||||
KeyboardShortcutManager.RegisterNewAppViewId();
|
KeyboardShortcutManager.RegisterNewAppViewId();
|
||||||
}
|
}
|
||||||
|
@ -630,6 +631,7 @@ namespace CalculatorApp
|
||||||
private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterReceivedEventArgs args)
|
private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterReceivedEventArgs args)
|
||||||
{
|
{
|
||||||
int viewId = Utilities.GetWindowId();
|
int viewId = Utilities.GetWindowId();
|
||||||
|
|
||||||
bool hit = s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts);
|
bool hit = s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts);
|
||||||
|
|
||||||
if (!hit || currentHonorShortcuts)
|
if (!hit || currentHonorShortcuts)
|
||||||
|
@ -644,6 +646,7 @@ namespace CalculatorApp
|
||||||
|
|
||||||
private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args)
|
private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args)
|
||||||
{
|
{
|
||||||
|
s_keyHandlerCount++;
|
||||||
if (args.Handled)
|
if (args.Handled)
|
||||||
{
|
{
|
||||||
return;
|
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)
|
private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args)
|
||||||
{
|
{
|
||||||
if (args.KeyStatus.IsKeyReleased)
|
if (args.KeyStatus.IsKeyReleased)
|
||||||
|
@ -831,6 +857,10 @@ namespace CalculatorApp
|
||||||
|
|
||||||
//private static Concurrency.reader_writer_lock s_keyboardShortcutMapLock;
|
//private static Concurrency.reader_writer_lock s_keyboardShortcutMapLock;
|
||||||
private static readonly object s_keyboardShortcutMapLockMutex = new object();
|
private static readonly object s_keyboardShortcutMapLockMutex = new object();
|
||||||
|
|
||||||
|
|
||||||
|
private static int s_keyHandlerCount;
|
||||||
|
private static bool s_deferredEnableShortcut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ namespace CalculatorApp
|
||||||
ViewMode newValue = m_model.Mode;
|
ViewMode newValue = m_model.Mode;
|
||||||
ViewMode previousMode = m_model.PreviousMode;
|
ViewMode previousMode = m_model.PreviousMode;
|
||||||
|
|
||||||
KeyboardShortcutManager.DisableShortcuts(false);
|
KeyboardShortcutManager.TryEnableShortcut();
|
||||||
|
|
||||||
if (newValue == ViewMode.Standard)
|
if (newValue == ViewMode.Standard)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue