From b7ccab67d17404d650536d9589c249b2f500ce45 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sat, 13 Apr 2024 12:53:33 -0500 Subject: [PATCH] handle lostfocus --- Flow.Launcher/HotkeyControl.xaml | 1 + Flow.Launcher/HotkeyControl.xaml.cs | 5 +++++ Flow.Launcher/ViewModel/HotkeyControlViewModel.cs | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/Flow.Launcher/HotkeyControl.xaml b/Flow.Launcher/HotkeyControl.xaml index 488b80202..c4a3d8986 100644 --- a/Flow.Launcher/HotkeyControl.xaml +++ b/Flow.Launcher/HotkeyControl.xaml @@ -100,6 +100,7 @@ IsChecked="{Binding Recording}" KeyboardNavigation.TabNavigation="Continue" PreviewKeyDown="OnPreviewKeyDown" + LostFocus="HotkeyBtn_OnLostFocus" Style="{StaticResource {x:Type ToggleButton}}"> diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index 071f844f4..c9fdaa007 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -93,5 +93,10 @@ namespace Flow.Launcher { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + private void HotkeyBtn_OnLostFocus(object sender, RoutedEventArgs e) + { + _ = ((HotkeyControlViewModel)DataContext).RegisterHotkey(); + } } } diff --git a/Flow.Launcher/ViewModel/HotkeyControlViewModel.cs b/Flow.Launcher/ViewModel/HotkeyControlViewModel.cs index 7d90e50b1..afc7d6a39 100644 --- a/Flow.Launcher/ViewModel/HotkeyControlViewModel.cs +++ b/Flow.Launcher/ViewModel/HotkeyControlViewModel.cs @@ -222,6 +222,11 @@ namespace Flow.Launcher.ViewModel container.Add(EmptyHotkey); } } + + public Task RegisterHotkey() + { + return SetHotkeyAsync(Hotkey, true); + } public Task SetHotkeyAsync(string? keyStr, bool triggerValidate = true) {