diff --git a/Source/GrasscutterTools/App.config b/Source/GrasscutterTools/App.config
index c72e11e..e7ee5ad 100644
--- a/Source/GrasscutterTools/App.config
+++ b/Source/GrasscutterTools/App.config
@@ -76,6 +76,9 @@
False
+
+ True
+
\ No newline at end of file
diff --git a/Source/GrasscutterTools/Forms/FormMain.cs b/Source/GrasscutterTools/Forms/FormMain.cs
index a4262a6..f468d04 100644
--- a/Source/GrasscutterTools/Forms/FormMain.cs
+++ b/Source/GrasscutterTools/Forms/FormMain.cs
@@ -587,6 +587,30 @@ namespace GrasscutterTools.Forms
if (i < ListPages.Items.Count)
ListPages.SelectedIndex = i;
}
+ else if (Common.KeyGo.IsEnabled == false)
+ {
+ foreach (var hotkeyItem in Common.KeyGo.Items)
+ {
+ if (!hotkeyItem.IsEnabled) continue;
+
+ var t = hotkeyItem.HotKey.LastIndexOf('+');
+ var key = (t >= 0) ? hotkeyItem.HotKey.Substring(t+1) : hotkeyItem.HotKey;
+ if (e.KeyCode != (Keys)Enum.Parse(typeof(Keys), key.Trim()))
+ continue;
+
+ if (t >= 0)
+ {
+ if (hotkeyItem.HotKey.Contains("Ctrl") && !e.Control)
+ continue;
+ if (hotkeyItem.HotKey.Contains("Shift") && !e.Shift)
+ continue;
+ if (hotkeyItem.HotKey.Contains("Alt") && !e.Alt)
+ continue;
+ }
+ BeginInvoke(new Func(() => RunRawCommands(hotkeyItem.Commands)));
+ break;
+ }
+ }
}
///
diff --git a/Source/GrasscutterTools/Pages/PageHotKey.Designer.cs b/Source/GrasscutterTools/Pages/PageHotKey.Designer.cs
index fdc0dcd..f6ecd60 100644
--- a/Source/GrasscutterTools/Pages/PageHotKey.Designer.cs
+++ b/Source/GrasscutterTools/Pages/PageHotKey.Designer.cs
@@ -34,6 +34,7 @@
this.ColHotKey = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ColCommand = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.GrpHotKeyList = new System.Windows.Forms.GroupBox();
+ this.ChkEnableGlobal = new System.Windows.Forms.CheckBox();
this.BtnRemove = new System.Windows.Forms.Button();
this.BtnAddOrUpdate = new System.Windows.Forms.Button();
this.TxtHotKey = new System.Windows.Forms.TextBox();
@@ -45,12 +46,12 @@
//
// LvHotKeyList
//
+ resources.ApplyResources(this.LvHotKeyList, "LvHotKeyList");
this.LvHotKeyList.CheckBoxes = true;
this.LvHotKeyList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ColTag,
this.ColHotKey,
this.ColCommand});
- resources.ApplyResources(this.LvHotKeyList, "LvHotKeyList");
this.LvHotKeyList.HideSelection = false;
this.LvHotKeyList.Name = "LvHotKeyList";
this.LvHotKeyList.UseCompatibleStateImageBehavior = false;
@@ -73,10 +74,20 @@
// GrpHotKeyList
//
resources.ApplyResources(this.GrpHotKeyList, "GrpHotKeyList");
+ this.GrpHotKeyList.Controls.Add(this.ChkEnableGlobal);
this.GrpHotKeyList.Controls.Add(this.LvHotKeyList);
this.GrpHotKeyList.Name = "GrpHotKeyList";
this.GrpHotKeyList.TabStop = false;
//
+ // ChkEnableGlobal
+ //
+ resources.ApplyResources(this.ChkEnableGlobal, "ChkEnableGlobal");
+ this.ChkEnableGlobal.Checked = true;
+ this.ChkEnableGlobal.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.ChkEnableGlobal.Name = "ChkEnableGlobal";
+ this.ChkEnableGlobal.UseVisualStyleBackColor = true;
+ this.ChkEnableGlobal.CheckedChanged += new System.EventHandler(this.ChkEnableGlobal_CheckedChanged);
+ //
// BtnRemove
//
resources.ApplyResources(this.BtnRemove, "BtnRemove");
@@ -127,6 +138,7 @@
this.Controls.Add(this.LblTagLabel);
this.Name = "PageHotKey";
this.GrpHotKeyList.ResumeLayout(false);
+ this.GrpHotKeyList.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -145,5 +157,6 @@
private System.Windows.Forms.Label LblHotKeyLabel;
private System.Windows.Forms.TextBox TxtTag;
private System.Windows.Forms.Label LblTagLabel;
+ private System.Windows.Forms.CheckBox ChkEnableGlobal;
}
}
diff --git a/Source/GrasscutterTools/Pages/PageHotKey.cs b/Source/GrasscutterTools/Pages/PageHotKey.cs
index 4818790..eb84495 100644
--- a/Source/GrasscutterTools/Pages/PageHotKey.cs
+++ b/Source/GrasscutterTools/Pages/PageHotKey.cs
@@ -53,6 +53,38 @@ namespace GrasscutterTools.Pages
///
private bool HotKeysChanged;
+ ///
+ /// 加载用户热键列表
+ ///
+ private List LoadKeyItems()
+ {
+ List list = null;
+ try
+ {
+ Logger.I(TAG, "Loading HotKey json file from: " + HotKeysFilePath);
+ list = JsonConvert.DeserializeObject>(File.ReadAllText(HotKeysFilePath));
+ }
+ catch (Exception ex)
+ {
+ Logger.E(TAG, "Parsing HotKeys.json failed", ex);
+ }
+
+ if (list == null || list.Count == 0)
+ {
+ // 默认把移动命令加到列表
+ list = new List
+ {
+ new("↑", "/tp ^ ^ ^10", "NumPad8", false),
+ new("↓", "/tp ^ ^ ^-10", "NumPad5", false),
+ new("←", "/tp ^-10 ^ ^", "NumPad4", false),
+ new("→", "/tp ^10 ^ ^", "NumPad6", false),
+ new("↑^↑", "/tp ~ ~10 ~", "NumPad0", false),
+ };
+ }
+
+ return list;
+ }
+
///
/// 初始化快捷键
///
@@ -62,15 +94,16 @@ namespace GrasscutterTools.Pages
return;
try
{
- Logger.I(TAG, "Loading HotKey json file from: " + HotKeysFilePath);
- Common.KeyGo.Items = JsonConvert.DeserializeObject>(File.ReadAllText(HotKeysFilePath));
+ // 还原设置
+ Common.KeyGo.IsEnabled = ChkEnableGlobal.Checked = Settings.Default.IsHotkeyEenabled;
+ Common.KeyGo.Items = LoadKeyItems();
LvHotKeyList.Items.AddRange(Common.KeyGo.Items.Select(HotKeyItemToViewItem).ToArray());
Logger.I(TAG, "Start Register All HotKeys");
Common.KeyGo.RegAllKey();
}
catch (Exception ex)
{
- Logger.W(TAG, "Parsing HotKeys.json failed.", ex);
+ Logger.W(TAG, "Failed to InitHotKeys", ex);
}
}
@@ -79,6 +112,8 @@ namespace GrasscutterTools.Pages
///
public override void OnClosed()
{
+ Settings.Default.IsHotkeyEenabled = Common.KeyGo.IsEnabled;
+
Logger.I(TAG, "Cancel all HotKeys");
Common.KeyGo.UnRegAllKey();
@@ -90,7 +125,7 @@ namespace GrasscutterTools.Pages
///
/// 将实体转为视图对象
///
- private static ListViewItem HotKeyItemToViewItem(HotKeyItem item) => new ListViewItem(new[]
+ private static ListViewItem HotKeyItemToViewItem(HotKeyItem item) => new(new[]
{
item.Tag,
item.HotKey,
@@ -130,12 +165,7 @@ namespace GrasscutterTools.Pages
var i = Common.KeyGo.Items.FindIndex(it => it.Tag == tag);
if (i == -1)
{
- var item = new HotKeyItem
- {
- Tag = tag,
- Commands = commands,
- HotKey = hotKey
- };
+ var item = new HotKeyItem(tag, commands, hotKey);
Logger.I(TAG, $"New HotKey item [{hotKey}]");
Common.KeyGo.AddHotKey(item);
LvHotKeyList.Items.Add(HotKeyItemToViewItem(item));
@@ -260,5 +290,22 @@ namespace GrasscutterTools.Pages
TxtHotKey.Tag = "";
TxtTag.Text = tag;
}
+
+ ///
+ /// 切换启用全局快捷键时触发
+ ///
+ private void ChkEnableGlobal_CheckedChanged(object sender, EventArgs e)
+ {
+ try
+ {
+ Common.KeyGo.IsEnabled = ChkEnableGlobal.Checked;
+ }
+ catch (Exception ex)
+ {
+ Logger.E(TAG, "Failed to switch global hotkeys", ex);
+ MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+
+ }
}
}
\ No newline at end of file
diff --git a/Source/GrasscutterTools/Pages/PageHotKey.en-US.resx b/Source/GrasscutterTools/Pages/PageHotKey.en-US.resx
index 3568632..421dfd3 100644
--- a/Source/GrasscutterTools/Pages/PageHotKey.en-US.resx
+++ b/Source/GrasscutterTools/Pages/PageHotKey.en-US.resx
@@ -126,6 +126,16 @@
Commands
+
+
+ 523, -2
+
+
+ 111, 21
+
+
+ Global HotKey
+
HotKeys
@@ -135,7 +145,6 @@
√ AddOrUpdate
-
50, 17
diff --git a/Source/GrasscutterTools/Pages/PageHotKey.resx b/Source/GrasscutterTools/Pages/PageHotKey.resx
index d5f2662..e4fa274 100644
--- a/Source/GrasscutterTools/Pages/PageHotKey.resx
+++ b/Source/GrasscutterTools/Pages/PageHotKey.resx
@@ -117,215 +117,92 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- 标签
-
-
-
- 150
-
-
- 快捷键
-
-
- 100
-
-
- 命令
-
-
- 350
-
-
-
- Fill
+
+ 0
-
- 3, 19
+
+ 100, 30
-
- 634, 178
+
+
+ 3
-
- 0
+
+ True
-
- LvHotKeyList
-
-
- System.Windows.Forms.ListView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- GrpHotKeyList
-
-
- 0
-
-
- Top, Bottom, Left, Right
-
-
- 3, 3
+
+ GrasscutterTools.Pages.BasePage, GrasscutterTools, Version=1.13.0.0, Culture=neutral, PublicKeyToken=de2b1c089621e923
640, 200
-
- 1
-
-
- 快捷执行列表
-
-
- GrpHotKeyList
-
-
- System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- $this
-
-
- 2
-
-
- Bottom, Right
-
-
- 543, 206
-
-
- 100, 30
-
-
- 5
-
-
- - 删除
-
-
- BtnRemove
-
-
- System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- $this
-
-
- 0
-
-
- Bottom, Right
-
-
- 387, 206
-
-
- 150, 30
-
-
- 4
-
-
- √ 添加或更新
+
+ 212, 213
BtnAddOrUpdate
-
- System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- $this
-
-
- 1
-
-
- Bottom, Left, Right
-
-
- 262, 210
-
-
- 119, 23
-
-
- 3
-
-
- Center
-
-
- TxtHotKey
-
-
- System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- $this
-
-
- 3
-
-
- Bottom, Left, Right
-
-
- True
-
-
- 212, 213
-
-
- 44, 17
-
-
- 2
-
-
- 快捷键
-
-
- LblHotKeyLabel
-
-
- System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- $this
-
-
- 5
-
-
- Bottom, Left, Right
-
-
- 41, 210
-
-
- 165, 23
+
+ 543, 206
1
-
- TxtTag
-
-
- System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
+
$this
+
+ System.Windows.Forms.ListView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 387, 206
+
+
+ 165, 23
+
+
+ $this
+
+
+ 547, -2
+
+
+ 44, 17
+
+
+ 快捷执行列表
+
+
+ 100
+
4
-
- Bottom, Left
+
+ $this
+
+
+ TxtHotKey
+
+
+ 5
+
+
+ System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+ Bottom, Left, Right
+
+
+ System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 3
True
@@ -333,55 +210,208 @@
3, 213
-
- 32, 17
+
+ 150, 30
-
+
+ 快捷键
+
+
0
-
- 标签
+
+ Bottom, Left
-
- LblTagLabel
-
-
- System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
+
$this
+
+ TxtTag
+
+
+ 2
+
+
+ 634, 178
+
6
-
- True
-
-
- 7, 17
+
+ LvHotKeyList
+
+
+ 0
ColTag
-
- System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 262, 210
-
- ColHotKey
+
+ 命令
-
- System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 119, 23
-
- ColCommand
+
+ System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ GrpHotKeyList
+
+
+ System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 5
+
+
+ Fill
+
+
+ System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ GrpHotKeyList
+
+
+ 快捷键
+
+
+ System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ BtnRemove
+
+
+ System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 标签
+
+
+ 全局快捷键
+
+
+ √ 添加或更新
+
+
+ 7, 17
+
+
+ 150
+
+
+ LblTagLabel
+
+
+ $this
+
+
+ 3, 19
+
+
+ True
+
+
+ 2
+
+
+ 1
+
+
+ 32, 17
+
+
+ ChkEnableGlobal
+
+
+ 4
+
+
+ System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
PageHotKey
-
- GrasscutterTools.Pages.BasePage, GrasscutterTools, Version=1.11.0.0, Culture=neutral, PublicKeyToken=de2b1c089621e923
+
+ Bottom, Left, Right
+
+ 1
+
+
+ Top, Bottom, Left, Right
+
+
+ ColHotKey
+
+
+ LblHotKeyLabel
+
+
+ 标签
+
+
+ ColCommand
+
+
+ 1
+
+
+ 87, 21
+
+
+ $this
+
+
+ - 删除
+
+
+ Bottom, Right
+
+
+ Bottom, Right
+
+
+ 350
+
+
+ 41, 210
+
+
+ Center
+
+
+ 0
+
+
+ GrpHotKeyList
+
+
+ 1
+
+
+ 3, 3
+
+
+ System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ Bottom, Left, Right
+
+
+ $this
+
+
+ Top, Right
+
+
+ True
+
\ No newline at end of file
diff --git a/Source/GrasscutterTools/Pages/PageHotKey.ru-RU.resx b/Source/GrasscutterTools/Pages/PageHotKey.ru-RU.resx
index 3568632..421dfd3 100644
--- a/Source/GrasscutterTools/Pages/PageHotKey.ru-RU.resx
+++ b/Source/GrasscutterTools/Pages/PageHotKey.ru-RU.resx
@@ -126,6 +126,16 @@
Commands
+
+
+ 523, -2
+
+
+ 111, 21
+
+
+ Global HotKey
+
HotKeys
@@ -135,7 +145,6 @@
√ AddOrUpdate
-
50, 17
diff --git a/Source/GrasscutterTools/Pages/PageHotKey.zh-TW.resx b/Source/GrasscutterTools/Pages/PageHotKey.zh-TW.resx
index 7d838b2..1d26080 100644
--- a/Source/GrasscutterTools/Pages/PageHotKey.zh-TW.resx
+++ b/Source/GrasscutterTools/Pages/PageHotKey.zh-TW.resx
@@ -123,6 +123,9 @@
快捷鍵
+
+ 全域快速鍵
+
快捷執行列表
diff --git a/Source/GrasscutterTools/Pages/PageOpenCommand.cs b/Source/GrasscutterTools/Pages/PageOpenCommand.cs
index f14e35a..0b065bb 100644
--- a/Source/GrasscutterTools/Pages/PageOpenCommand.cs
+++ b/Source/GrasscutterTools/Pages/PageOpenCommand.cs
@@ -24,9 +24,6 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
-
-using Eavesdrop;
-
using GrasscutterTools.DispatchServer;
using GrasscutterTools.DispatchServer.Model;
using GrasscutterTools.Game;
diff --git a/Source/GrasscutterTools/Properties/Settings.Designer.cs b/Source/GrasscutterTools/Properties/Settings.Designer.cs
index ec46169..89fd0e2 100644
--- a/Source/GrasscutterTools/Properties/Settings.Designer.cs
+++ b/Source/GrasscutterTools/Properties/Settings.Designer.cs
@@ -286,5 +286,17 @@ namespace GrasscutterTools.Properties {
this["IsUpgraded"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]
+ public bool IsHotkeyEenabled {
+ get {
+ return ((bool)(this["IsHotkeyEenabled"]));
+ }
+ set {
+ this["IsHotkeyEenabled"] = value;
+ }
+ }
}
}
diff --git a/Source/GrasscutterTools/Properties/Settings.settings b/Source/GrasscutterTools/Properties/Settings.settings
index 23ec6bf..617f771 100644
--- a/Source/GrasscutterTools/Properties/Settings.settings
+++ b/Source/GrasscutterTools/Properties/Settings.settings
@@ -68,5 +68,8 @@
False
+
+ True
+
\ No newline at end of file
diff --git a/Source/GrasscutterTools/Utils/HotKeyItem.cs b/Source/GrasscutterTools/Utils/HotKeyItem.cs
index 3d70f82..a88756d 100644
--- a/Source/GrasscutterTools/Utils/HotKeyItem.cs
+++ b/Source/GrasscutterTools/Utils/HotKeyItem.cs
@@ -26,6 +26,18 @@ namespace GrasscutterTools.Utils
///
internal class HotKeyItem
{
+ public HotKeyItem()
+ {
+ }
+
+ public HotKeyItem(string tag, string commands, string hotKey, bool isEnabled = true)
+ {
+ Tag = tag;
+ Commands = commands;
+ HotKey = hotKey;
+ IsEnabled = isEnabled;
+ }
+
///
/// Gets or sets the hot key identifier.
///
diff --git a/Source/GrasscutterTools/Utils/KeyGo.cs b/Source/GrasscutterTools/Utils/KeyGo.cs
index dd977be..52878fd 100644
--- a/Source/GrasscutterTools/Utils/KeyGo.cs
+++ b/Source/GrasscutterTools/Utils/KeyGo.cs
@@ -36,12 +36,28 @@ namespace GrasscutterTools.Utils
}
#region Member
-
+
private static int _regMaxId;
private readonly IntPtr FormHandle;
- public List Items { get; set; } = new List();
+ private bool _isEnabled;
+
+ public List Items { get; set; } = new();
+
+ ///
+ /// 全局热键是否启用
+ ///
+ 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);
}