Add hotkey global switch

This commit is contained in:
2023-09-29 15:04:30 +08:00
parent 1c49c41b71
commit 749f324f7d
13 changed files with 414 additions and 236 deletions

View File

@@ -26,6 +26,18 @@ namespace GrasscutterTools.Utils
/// </summary>
internal class HotKeyItem
{
public HotKeyItem()
{
}
public HotKeyItem(string tag, string commands, string hotKey, bool isEnabled = true)
{
Tag = tag;
Commands = commands;
HotKey = hotKey;
IsEnabled = isEnabled;
}
/// <summary>
/// Gets or sets the hot key identifier.
/// </summary>

View File

@@ -36,12 +36,28 @@ namespace GrasscutterTools.Utils
}
#region Member
private static int _regMaxId;
private readonly IntPtr FormHandle;
public List<HotKeyItem> Items { get; set; } = new List<HotKeyItem>();
private bool _isEnabled;
public List<HotKeyItem> Items { get; set; } = new();
/// <summary>
/// 全局热键是否启用
/// </summary>
public bool IsEnabled
{
get => _isEnabled;
set
{
_isEnabled = value;
if (value) RegAllKey();
else UnRegAllKey();
}
}
#endregion Member
@@ -220,7 +236,7 @@ namespace GrasscutterTools.Utils
if (item is null)
throw new ArgumentNullException(nameof(item));
if (item.IsEnabled)
if (_isEnabled && item.IsEnabled)
RegKey(item);
Items.Add(item);
}
@@ -251,7 +267,7 @@ namespace GrasscutterTools.Utils
// 重新注册
if (item.HotKeyId != 0)
UnRegKey(item);
if (item.IsEnabled)
if (_isEnabled && item.IsEnabled)
RegKey(item);
}