diff --git a/Ink Canvas/Windows/HotkeyItem.xaml.cs b/Ink Canvas/Windows/HotkeyItem.xaml.cs index 2dea883c..63cda413 100644 --- a/Ink Canvas/Windows/HotkeyItem.xaml.cs +++ b/Ink Canvas/Windows/HotkeyItem.xaml.cs @@ -77,12 +77,21 @@ namespace Ink_Canvas.Windows } } + private static HotkeyItem _activeCaptureItem; + private void StartHotkeyCapture() { + if (_activeCaptureItem != null && _activeCaptureItem != this) + { + _activeCaptureItem.StopHotkeyCapture(); + } + _activeCaptureItem = this; + CurrentHotkeyTextBlock.Text = "请按键..."; Focus(); KeyDown += HotkeyItem_KeyDown; KeyUp += HotkeyItem_KeyUp; + LostFocus += HotkeyItem_LostFocus; } private void StopHotkeyCapture() @@ -90,6 +99,16 @@ namespace Ink_Canvas.Windows UpdateHotkeyDisplay(); KeyDown -= HotkeyItem_KeyDown; KeyUp -= HotkeyItem_KeyUp; + LostFocus -= HotkeyItem_LostFocus; + if (_activeCaptureItem == this) + { + _activeCaptureItem = null; + } + } + + private void HotkeyItem_LostFocus(object sender, RoutedEventArgs e) + { + StopHotkeyCapture(); } private void HotkeyItem_KeyDown(object sender, KeyEventArgs e) diff --git a/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs b/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs index b620c7c6..b6baa9d7 100644 --- a/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs @@ -90,6 +90,11 @@ namespace Ink_Canvas.Windows.SettingsViews.Pages { try { + foreach (var hotkeyItem in _hotkeyItems.Values) + { + hotkeyItem.SetCurrentHotkey(Key.None, ModifierKeys.None); + } + if (_hotkeyManager != null) { var configHotkeys = _hotkeyManager.GetHotkeysFromConfigFile();