diff --git a/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs b/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs index 64143f716a..d405d52d00 100644 --- a/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs +++ b/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs @@ -79,6 +79,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library } } + public bool GetDisposedState() => disposedValue; + public void Dispose() { Dispose(disposing: true); diff --git a/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs b/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs index 52f6750684..38ae3adb59 100644 --- a/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs +++ b/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs @@ -89,6 +89,8 @@ namespace Microsoft.PowerToys.Settings.UI.Controls hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents); ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse(); + App.GetSettingsWindow().Activated += ShortcutDialog_SettingsWindow_Activated; + // We create the Dialog in C# because doing it in XAML is giving WinUI/XAML Island bugs when using dark theme. shortcutDialog = new ContentDialog { @@ -111,6 +113,8 @@ namespace Microsoft.PowerToys.Settings.UI.Controls shortcutDialog.Opened -= ShortcutDialog_Opened; shortcutDialog.Closing -= ShortcutDialog_Closing; + App.GetSettingsWindow().Activated -= ShortcutDialog_SettingsWindow_Activated; + // Dispose the HotkeySettingsControlHook object to terminate the hook threads when the textbox is unloaded hook.Dispose(); } @@ -336,6 +340,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls c.Keys = HotkeySettings.GetKeysList(); shortcutDialog.XamlRoot = this.XamlRoot; + shortcutDialog.RequestedTheme = this.ActualTheme; await shortcutDialog.ShowAsync(); } @@ -363,6 +368,21 @@ namespace Microsoft.PowerToys.Settings.UI.Controls } } + private void ShortcutDialog_SettingsWindow_Activated(object sender, WindowActivatedEventArgs args) + { + args.Handled = true; + if (args.WindowActivationState != WindowActivationState.Deactivated && hook.GetDisposedState() == true) + { + // If the PT settings window gets focussed/activated again, we enable the keyboard hook to catch the keyboard input. + hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents); + } + else if (args.WindowActivationState == WindowActivationState.Deactivated && hook.GetDisposedState() == false) + { + // If the PT settings window lost focus/activation, we disable the keyboard hook to allow keyboard input on other windows. + hook.Dispose(); + } + } + private void ShortcutDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) { _isActive = false; diff --git a/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml b/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml index 2ea9aa3d94..0429f5dae4 100644 --- a/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml +++ b/src/settings-ui/Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml @@ -56,39 +56,14 @@ VerticalAlignment="Top" Orientation="Vertical" Spacing="8"> - + - - - - - - + - - - - - Activation shortcut - + Invalid shortcut Only shortcuts that start with **Windows key**, **Ctrl**, **Alt** or **Shift** are valid. + The ** sequences are used for text formatting of the key names. Don't remove them on translation. All monitors must have the same DPI scaling and will be treated as one large combined rectangle which contains all monitors @@ -3115,4 +3116,4 @@ Activate by holding the key for the character you want to add an accent to, then Launch Registry Preview - + \ No newline at end of file