From 3b497ef3f8592e53eebd57cf63847be7b7c5494d Mon Sep 17 00:00:00 2001 From: Huoxing-Rusty <220455872+Huoxing-Rusty@users.noreply.github.com> Date: Sat, 26 Sep 2026 02:06:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=BC=A0?= =?UTF-8?q?=E6=A0=87=E6=A8=A1=E5=BC=8F=E4=BF=9D=E7=95=99=E7=BB=98=E5=9B=BE?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=EF=BC=8C=E8=A7=A3=E5=86=B3Alt+D?= =?UTF-8?q?=E5=9C=A8=E9=BC=A0=E6=A0=87=E6=A8=A1=E5=BC=8F=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=9B=9E=E6=89=B9=E6=B3=A8=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E9=81=BF=E5=85=8D=E5=BD=B1=E5=93=8D?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E6=8C=89=E9=94=AE=E7=A9=BF=E9=80=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Helpers/GlobalHotkeyManager.cs | 49 ++++++++++++++++--- .../Properties/HotkeyStrings.Designer.cs | 4 ++ .../Properties/HotkeyStrings.en-US.resx | 6 +++ Ink Canvas/Properties/HotkeyStrings.resx | 6 +++ .../Properties/HotkeyStrings.zh-ME.resx | 6 +++ Ink Canvas/Properties/Strings.cs | 2 + Ink Canvas/Resources/Settings.cs | 3 ++ .../SettingsViews/Pages/HotkeyPage.xaml | 7 +++ .../SettingsViews/Pages/HotkeyPage.xaml.cs | 34 ++++++++++--- 9 files changed, 102 insertions(+), 15 deletions(-) diff --git a/Ink Canvas/Helpers/GlobalHotkeyManager.cs b/Ink Canvas/Helpers/GlobalHotkeyManager.cs index 61cbe3d5d..7077b7ad2 100644 --- a/Ink Canvas/Helpers/GlobalHotkeyManager.cs +++ b/Ink Canvas/Helpers/GlobalHotkeyManager.cs @@ -23,6 +23,14 @@ public class GlobalHotkeyManager : IDisposable private readonly MainWindow _mainWindow; private bool _isDisposed; private bool _hotkeysShouldBeRegistered = true; // 启动时注册热键 + private bool _isContextHotkeyDisabled; + private bool _allowContextExemptRegistration; + + private static readonly HashSet DrawingHotkeyNames = new HashSet(StringComparer.Ordinal) + { + "DrawTool", "EraserTool", "BlackboardTool", "QuitDrawTool", + "Pen1", "Pen2", "Pen3", "Pen4", "Pen5", "DrawLine" + }; // 多屏幕支持相关字段 private Screen _currentScreen; @@ -70,7 +78,7 @@ public bool RegisterHotkey(string hotkeyName, Key key, ModifierKeys modifiers, A return false; // 检查是否应该注册热键(基于屏幕和模式) - if (!ShouldRegisterHotkeys()) + if (!ShouldRegisterHotkeys() && !_allowContextExemptRegistration) { return false; } @@ -469,6 +477,7 @@ public void EnableHotkeyRegistration() { try { + _isContextHotkeyDisabled = false; if (!_hotkeysShouldBeRegistered) { _hotkeysShouldBeRegistered = true; @@ -510,6 +519,7 @@ public void DisableHotkeyRegistration() { try { + _isContextHotkeyDisabled = false; if (_hotkeysShouldBeRegistered) { _hotkeysShouldBeRegistered = false; @@ -543,11 +553,12 @@ private void DisableHotkeyRegistrationForContext() { try { - if (!_hotkeysShouldBeRegistered) + if (!_hotkeysShouldBeRegistered && !_isContextHotkeyDisabled) { return; } + _isContextHotkeyDisabled = true; _hotkeysShouldBeRegistered = false; // 停止鼠标位置监控定时器 @@ -558,6 +569,11 @@ private void DisableHotkeyRegistrationForContext() // 仅注销内置快捷键,保留插件热键 UnregisterAllHotkeys(false); + + if (MainWindow.Settings.Appearance.KeepDrawingHotkeysInMouseMode) + { + RegisterDrawingHotkeysForMouseMode(); + } } catch (Exception ex) { @@ -565,6 +581,28 @@ private void DisableHotkeyRegistrationForContext() } } + private void RegisterDrawingHotkeysForMouseMode() + { + try + { + var drawingHotkeys = GetHotkeysFromConfigFile(); + _allowContextExemptRegistration = true; + foreach (var hotkey in drawingHotkeys) + { + if (!DrawingHotkeyNames.Contains(hotkey.Name)) + continue; + + var action = GetActionByName(hotkey.Name); + if (action != null) + RegisterHotkey(hotkey.Name, hotkey.Key, hotkey.Modifiers, action); + } + } + finally + { + _allowContextExemptRegistration = false; + } + } + /// /// 根据当前工具模式更新快捷键状态 /// 在工具切换时调用此方法 @@ -599,11 +637,8 @@ public void UpdateHotkeyStateForToolMode(bool isMouseMode) { // 非鼠标模式下启用快捷键 EnableHotkeyRegistration(); - - if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0) - { - LoadHotkeysFromSettings(); - } + _isContextHotkeyDisabled = false; + LoadHotkeysFromSettings(); } } catch (Exception ex) diff --git a/Ink Canvas/Properties/HotkeyStrings.Designer.cs b/Ink Canvas/Properties/HotkeyStrings.Designer.cs index e4158184b..19922ffa2 100644 --- a/Ink Canvas/Properties/HotkeyStrings.Designer.cs +++ b/Ink Canvas/Properties/HotkeyStrings.Designer.cs @@ -50,6 +50,10 @@ public static string GetString(string key) public static string Hotkey_EnableHotkeysInMouseModeHint => ResourceManager.GetString(nameof(Hotkey_EnableHotkeysInMouseModeHint), _resourceCulture); + public static string Hotkey_KeepDrawingHotkeysInMouseMode => ResourceManager.GetString(nameof(Hotkey_KeepDrawingHotkeysInMouseMode), _resourceCulture); + + public static string Hotkey_KeepDrawingHotkeysInMouseModeHint => ResourceManager.GetString(nameof(Hotkey_KeepDrawingHotkeysInMouseModeHint), _resourceCulture); + public static string Hotkey_PassThroughMouseWheelInDrawingMode => ResourceManager.GetString(nameof(Hotkey_PassThroughMouseWheelInDrawingMode), _resourceCulture); public static string Hotkey_PassThroughMouseWheelInDrawingModeHint => ResourceManager.GetString(nameof(Hotkey_PassThroughMouseWheelInDrawingModeHint), _resourceCulture); diff --git a/Ink Canvas/Properties/HotkeyStrings.en-US.resx b/Ink Canvas/Properties/HotkeyStrings.en-US.resx index 128978539..ba6fed951 100644 --- a/Ink Canvas/Properties/HotkeyStrings.en-US.resx +++ b/Ink Canvas/Properties/HotkeyStrings.en-US.resx @@ -57,6 +57,12 @@ When on, hotkeys will work even in mouse mode + + Keep drawing hotkeys in mouse mode + + + When the option above is off, keep drawing tool hotkeys to enter annotation mode; other hotkeys remain available to the foreground app + Pass-through mouse wheel in drawing mode diff --git a/Ink Canvas/Properties/HotkeyStrings.resx b/Ink Canvas/Properties/HotkeyStrings.resx index 45916aefa..cdf2e928e 100644 --- a/Ink Canvas/Properties/HotkeyStrings.resx +++ b/Ink Canvas/Properties/HotkeyStrings.resx @@ -57,6 +57,12 @@ 开启后,即使在鼠标模式下快捷键也会生效 + + 鼠标模式下保留绘图快捷键 + + + 即使关闭上方选项时,仍启用绘图工具快捷键,使从鼠标模式进入批注;其他快捷键继续交给前台应用 + 绘制模式下滚轮穿透 diff --git a/Ink Canvas/Properties/HotkeyStrings.zh-ME.resx b/Ink Canvas/Properties/HotkeyStrings.zh-ME.resx index eec5eccf4..a1bf2bf14 100644 --- a/Ink Canvas/Properties/HotkeyStrings.zh-ME.resx +++ b/Ink Canvas/Properties/HotkeyStrings.zh-ME.resx @@ -57,6 +57,12 @@ 开启后,鼠标形态下快捷键照样生效,不放过任何一个骚操作 + + 鼠标形态绘图骚操作照样生效 + + + 关闭上方选项时,依然阔以用绘图骚操作进入批注招式,其他快捷键不受影响,中 + 画画时让鼠标滚轮穿透下去 diff --git a/Ink Canvas/Properties/Strings.cs b/Ink Canvas/Properties/Strings.cs index b344cb0b2..ac0fe5bf8 100644 --- a/Ink Canvas/Properties/Strings.cs +++ b/Ink Canvas/Properties/Strings.cs @@ -572,6 +572,8 @@ public static class Strings dict["Hotkey_MouseMode"] = ("HotkeyStrings", "Hotkey_MouseMode"); dict["Hotkey_EnableHotkeysInMouseMode"] = ("HotkeyStrings", "Hotkey_EnableHotkeysInMouseMode"); dict["Hotkey_EnableHotkeysInMouseModeHint"] = ("HotkeyStrings", "Hotkey_EnableHotkeysInMouseModeHint"); + dict["Hotkey_KeepDrawingHotkeysInMouseMode"] = ("HotkeyStrings", "Hotkey_KeepDrawingHotkeysInMouseMode"); + dict["Hotkey_KeepDrawingHotkeysInMouseModeHint"] = ("HotkeyStrings", "Hotkey_KeepDrawingHotkeysInMouseModeHint"); dict["Hotkey_PassThroughMouseWheelInDrawingMode"] = ("HotkeyStrings", "Hotkey_PassThroughMouseWheelInDrawingMode"); dict["Hotkey_PassThroughMouseWheelInDrawingModeHint"] = ("HotkeyStrings", "Hotkey_PassThroughMouseWheelInDrawingModeHint"); dict["Hotkey_EnablePPTPageKeyHook"] = ("HotkeyStrings", "Hotkey_EnablePPTPageKeyHook"); diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index 9acaa277c..4afd3b300 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -876,6 +876,9 @@ public class Appearance [JsonProperty("enableHotkeysInMouseMode")] public bool EnableHotkeysInMouseMode { get; set; } = false; + [JsonProperty("keepDrawingHotkeysInMouseMode")] + public bool KeepDrawingHotkeysInMouseMode { get; set; } = false; + [JsonProperty("passThroughMouseWheelInDrawingMode")] public bool PassThroughMouseWheelInDrawingMode { get; set; } = false; diff --git a/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml b/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml index 7ea4b02cb..d423015c4 100644 --- a/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml +++ b/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml @@ -48,6 +48,13 @@ SwitchName="ToggleSwitchEnableHotkeysInMouseMode" Toggled="ToggleSwitchEnableHotkeysInMouseMode_Toggled" /> + + Date: Sat, 26 Sep 2026 02:32:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=20UserPreferenceC?= =?UTF-8?q?hanged=20=E7=A9=BA=E5=8F=82=E6=95=B0=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow_cs/MW_AutoTheme.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs index d8e930596..e015a8da0 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs @@ -292,7 +292,9 @@ void SetFloatingBarButtonBrush(ToolbarImageButton btn) private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) { // 只关心外观类偏好变化;键盘/鼠标/电源等类别与主题无关 - if (e.Category != UserPreferenceCategory.General) return; + // e 为空时表示程序加载设置后的内部初始化调用,此时直接建立主题基线。 + if (e != null && e.Category != UserPreferenceCategory.General) return; + if (Dispatcher.HasShutdownStarted || Dispatcher.HasShutdownFinished) return; // SystemEvents 的事件不保证在 UI 线程触发,统一调度回 UI 线程 Dispatcher.BeginInvoke(new Action(CheckSystemThemeSwitch)); } From 4dcf002db3a5f9a3d4647dd20117c21fb2f411c3 Mon Sep 17 00:00:00 2001 From: Huoxing-Rusty <220455872+Huoxing-Rusty@users.noreply.github.com> Date: Mon, 12 Oct 2026 01:08:36 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E7=BB=98=E5=9B=BE=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Helpers/GlobalHotkeyManager.cs | 27 +++++++++---------- Ink Canvas/MainWindow_cs/MW_AutoTheme.cs | 1 - .../SettingsViews/Pages/HotkeyPage.xaml.cs | 7 +---- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/Ink Canvas/Helpers/GlobalHotkeyManager.cs b/Ink Canvas/Helpers/GlobalHotkeyManager.cs index 973a45648..b8f5c7b12 100644 --- a/Ink Canvas/Helpers/GlobalHotkeyManager.cs +++ b/Ink Canvas/Helpers/GlobalHotkeyManager.cs @@ -522,22 +522,16 @@ public void DisableHotkeyRegistration() try { _isContextHotkeyDisabled = false; - if (_hotkeysShouldBeRegistered) - { - _hotkeysShouldBeRegistered = false; - - // 停止鼠标位置监控定时器 - if (_mousePositionTimer != null && _mousePositionTimer.IsEnabled) - { - _mousePositionTimer.Stop(); - } + _hotkeysShouldBeRegistered = false; - // 注销所有快捷键(含插件热键——这是用户/插件的显式停用) - UnregisterAllHotkeys(true); - } - else + // 停止鼠标位置监控定时器 + if (_mousePositionTimer != null && _mousePositionTimer.IsEnabled) { + _mousePositionTimer.Stop(); } + + // 鼠标模式可能仍保留绘图热键,显式停用必须无条件注销全部热键。 + UnregisterAllHotkeys(true); } catch (Exception ex) { @@ -639,8 +633,11 @@ public void UpdateHotkeyStateForToolMode(bool isMouseMode) { // 非鼠标模式下启用快捷键 EnableHotkeyRegistration(); - _isContextHotkeyDisabled = false; - LoadHotkeysFromSettings(); + + if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0) + { + LoadHotkeysFromSettings(); + } } } catch (Exception ex) diff --git a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs index 2da73a503..fe6d930c9 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs @@ -298,7 +298,6 @@ private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceCha // e 为 null 表示由代码主动调用(如设置加载完成后的主题刷新),此时跳过类别过滤 // 只关心外观类偏好变化;键盘/鼠标/电源等类别与主题无关 if (e != null && e.Category != UserPreferenceCategory.General) return; - if (Dispatcher.HasShutdownStarted || Dispatcher.HasShutdownFinished) return; // SystemEvents 的事件不保证在 UI 线程触发,统一调度回 UI 线程 Dispatcher.BeginInvoke(new Action(CheckSystemThemeSwitch)); } diff --git a/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs b/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs index e5f1a6c72..fcb961a4e 100644 --- a/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/Pages/HotkeyPage.xaml.cs @@ -410,10 +410,5 @@ private void BtnSave_Click(object sender, RoutedEventArgs e) MessageBoxButton.OK, MessageBoxImage.Error); } } - - private void CardKeepDrawingHotkeysInMouseMode_Loaded(object sender, RoutedEventArgs e) - { - - } } -} \ No newline at end of file +}