diff --git a/Ink Canvas/Helpers/GlobalHotkeyManager.cs b/Ink Canvas/Helpers/GlobalHotkeyManager.cs index e4bc400e..b8f5c7b1 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; } @@ -471,6 +479,7 @@ public void EnableHotkeyRegistration() { try { + _isContextHotkeyDisabled = false; if (!_hotkeysShouldBeRegistered) { _hotkeysShouldBeRegistered = true; @@ -512,22 +521,17 @@ public void DisableHotkeyRegistration() { try { - if (_hotkeysShouldBeRegistered) - { - _hotkeysShouldBeRegistered = false; - - // 停止鼠标位置监控定时器 - if (_mousePositionTimer != null && _mousePositionTimer.IsEnabled) - { - _mousePositionTimer.Stop(); - } + _isContextHotkeyDisabled = false; + _hotkeysShouldBeRegistered = false; - // 注销所有快捷键(含插件热键——这是用户/插件的显式停用) - UnregisterAllHotkeys(true); - } - else + // 停止鼠标位置监控定时器 + if (_mousePositionTimer != null && _mousePositionTimer.IsEnabled) { + _mousePositionTimer.Stop(); } + + // 鼠标模式可能仍保留绘图热键,显式停用必须无条件注销全部热键。 + UnregisterAllHotkeys(true); } catch (Exception ex) { @@ -545,11 +549,12 @@ private void DisableHotkeyRegistrationForContext() { try { - if (!_hotkeysShouldBeRegistered) + if (!_hotkeysShouldBeRegistered && !_isContextHotkeyDisabled) { return; } + _isContextHotkeyDisabled = true; _hotkeysShouldBeRegistered = false; // 停止鼠标位置监控定时器 @@ -560,6 +565,11 @@ private void DisableHotkeyRegistrationForContext() // 仅注销内置快捷键,保留插件热键 UnregisterAllHotkeys(false); + + if (MainWindow.Settings.Appearance.KeepDrawingHotkeysInMouseMode) + { + RegisterDrawingHotkeysForMouseMode(); + } } catch (Exception ex) { @@ -567,6 +577,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; + } + } + /// /// 根据当前工具模式更新快捷键状态 /// 在工具切换时调用此方法 diff --git a/Ink Canvas/Properties/HotkeyStrings.Designer.cs b/Ink Canvas/Properties/HotkeyStrings.Designer.cs index e4158184..19922ffa 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 12897853..ba6fed95 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 45916aef..cdf2e928 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 eec5eccf..a1bf2bf1 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 70d80706..6cefd7bc 100644 --- a/Ink Canvas/Properties/Strings.cs +++ b/Ink Canvas/Properties/Strings.cs @@ -573,6 +573,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 d6c62b15..29134ada 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -895,6 +895,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 7ea4b02c..d423015c 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" /> + +