mirror of
https://github.com/jie65535/KeyGo.git
synced 2025-06-02 17:39:13 +08:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
86a794f83d | |||
![]() |
dd6ddb1784 |
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
70
KeyGo/FormMain.Designer.cs
generated
70
KeyGo/FormMain.Designer.cs
generated
@ -38,12 +38,19 @@ namespace KeyGo
|
||||
this.TSMICloseToHide = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMIPowerBoot = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMIExit = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMITriggerCountStatistics = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMIConfigFile = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMIExportConfig = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMIImportConfig = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMICopyConfig = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.TSMIPasteConfig = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.FLPHotKeys.SuspendLayout();
|
||||
this.contextMenuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// FLPHotKeys
|
||||
//
|
||||
this.FLPHotKeys.AllowDrop = true;
|
||||
this.FLPHotKeys.AutoScroll = true;
|
||||
this.FLPHotKeys.BackColor = System.Drawing.Color.White;
|
||||
this.FLPHotKeys.Controls.Add(this.BtnAdd);
|
||||
@ -54,6 +61,8 @@ namespace KeyGo
|
||||
this.FLPHotKeys.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.FLPHotKeys.Size = new System.Drawing.Size(488, 197);
|
||||
this.FLPHotKeys.TabIndex = 0;
|
||||
this.FLPHotKeys.DragDrop += new System.Windows.Forms.DragEventHandler(this.FLPHotKeys_DragDrop);
|
||||
this.FLPHotKeys.DragEnter += new System.Windows.Forms.DragEventHandler(this.FLPHotKeys_DragEnter);
|
||||
//
|
||||
// BtnAdd
|
||||
//
|
||||
@ -75,17 +84,19 @@ namespace KeyGo
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.TSMIConfigFile,
|
||||
this.TSMITriggerCountStatistics,
|
||||
this.TSMICloseToHide,
|
||||
this.TSMIPowerBoot,
|
||||
this.TSMIExit});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(149, 70);
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(181, 136);
|
||||
//
|
||||
// TSMICloseToHide
|
||||
//
|
||||
this.TSMICloseToHide.CheckOnClick = true;
|
||||
this.TSMICloseToHide.Name = "TSMICloseToHide";
|
||||
this.TSMICloseToHide.Size = new System.Drawing.Size(148, 22);
|
||||
this.TSMICloseToHide.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMICloseToHide.Text = "关闭为最小化";
|
||||
this.TSMICloseToHide.CheckedChanged += new System.EventHandler(this.TSMICloseToHide_CheckedChanged);
|
||||
//
|
||||
@ -93,17 +104,62 @@ namespace KeyGo
|
||||
//
|
||||
this.TSMIPowerBoot.CheckOnClick = true;
|
||||
this.TSMIPowerBoot.Name = "TSMIPowerBoot";
|
||||
this.TSMIPowerBoot.Size = new System.Drawing.Size(148, 22);
|
||||
this.TSMIPowerBoot.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMIPowerBoot.Text = "开机自启动";
|
||||
this.TSMIPowerBoot.CheckedChanged += new System.EventHandler(this.TSMIPowerBoot_CheckedChanged);
|
||||
//
|
||||
// TSMIExit
|
||||
//
|
||||
this.TSMIExit.Name = "TSMIExit";
|
||||
this.TSMIExit.Size = new System.Drawing.Size(148, 22);
|
||||
this.TSMIExit.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMIExit.Text = "退出";
|
||||
this.TSMIExit.Click += new System.EventHandler(this.TSMIExit_Click);
|
||||
//
|
||||
// TSMIConfigFile
|
||||
//
|
||||
this.TSMIConfigFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.TSMIExportConfig,
|
||||
this.TSMIImportConfig,
|
||||
this.TSMICopyConfig,
|
||||
this.TSMIPasteConfig});
|
||||
this.TSMIConfigFile.Name = "TSMIConfigFile";
|
||||
this.TSMIConfigFile.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMIConfigFile.Text = "配置文件";
|
||||
//
|
||||
// TSMIExportConfig
|
||||
//
|
||||
this.TSMIExportConfig.Name = "TSMIExportConfig";
|
||||
this.TSMIExportConfig.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMIExportConfig.Text = "导出文件";
|
||||
this.TSMIExportConfig.Click += new System.EventHandler(this.TSMIExportConfig_Click);
|
||||
//
|
||||
// TSMIImportConfig
|
||||
//
|
||||
this.TSMIImportConfig.Name = "TSMIImportConfig";
|
||||
this.TSMIImportConfig.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMIImportConfig.Text = "导入文件";
|
||||
this.TSMIImportConfig.Click += new System.EventHandler(this.TSMIImportConfig_Click);
|
||||
//
|
||||
// TSMICopyConfig
|
||||
//
|
||||
this.TSMICopyConfig.Name = "TSMICopyConfig";
|
||||
this.TSMICopyConfig.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMICopyConfig.Text = "复制到剪切板";
|
||||
this.TSMICopyConfig.Click += new System.EventHandler(this.TSMICopyConfig_Click);
|
||||
//
|
||||
// TSMIPasteConfig
|
||||
//
|
||||
this.TSMIPasteConfig.Name = "TSMIPasteConfig";
|
||||
this.TSMIPasteConfig.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMIPasteConfig.Text = "从剪切板读入";
|
||||
this.TSMIPasteConfig.Click += new System.EventHandler(this.TSMIPasteConfig_Click);
|
||||
// TSMITriggerCountStatistics
|
||||
//
|
||||
this.TSMITriggerCountStatistics.Name = "TSMITriggerCountStatistics";
|
||||
this.TSMITriggerCountStatistics.Size = new System.Drawing.Size(180, 22);
|
||||
this.TSMITriggerCountStatistics.Text = "触发次数统计";
|
||||
this.TSMITriggerCountStatistics.Click += new System.EventHandler(this.TSMITriggerCountStatistics_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
||||
@ -137,6 +193,12 @@ namespace KeyGo
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMIExit;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMIPowerBoot;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMICloseToHide;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMIConfigFile;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMIExportConfig;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMIImportConfig;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMICopyConfig;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMIPasteConfig;
|
||||
private System.Windows.Forms.ToolStripMenuItem TSMITriggerCountStatistics;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@ -103,7 +105,8 @@ namespace KeyGo
|
||||
private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
_KeyGo.UnRegAllKey();
|
||||
SaveHotKeyItems(_KeyGo);
|
||||
// 关闭后不用保存,修改时保存即可
|
||||
//SaveHotKeyItems(_KeyGo);
|
||||
}
|
||||
|
||||
#endregion 窗体事件
|
||||
@ -192,17 +195,7 @@ namespace KeyGo
|
||||
var frm = new FormHotKey();
|
||||
if (frm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
var item = frm.HotKeyItem;
|
||||
_KeyGo.AddHotKey(item);
|
||||
FLP_AddItem(item);
|
||||
SaveHotKeyItems(_KeyGo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("在添加新的热键时异常:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
AddHotKeyItem(frm.HotKeyItem);
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,6 +219,30 @@ namespace KeyGo
|
||||
FLPHotKeys.Controls.SetChildIndex(BtnAdd, i1);
|
||||
}
|
||||
|
||||
private void AddHotKeyItem(HotKeyItem item, bool save = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
_KeyGo.AddHotKey(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (item.Enabled)
|
||||
{
|
||||
// 禁用后再添加
|
||||
item.Enabled = false;
|
||||
_KeyGo.AddHotKey(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("在添加新的热键时异常:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
FLP_AddItem(item);
|
||||
if (save) SaveHotKeyItems(_KeyGo);
|
||||
}
|
||||
|
||||
#endregion 热键管理
|
||||
|
||||
#region 托盘图标管理
|
||||
@ -288,6 +305,11 @@ namespace KeyGo
|
||||
SaveAppConfig(_AppConfig);
|
||||
}
|
||||
|
||||
private void TSMITriggerCountStatistics_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show(string.Join(Environment.NewLine, _KeyGo.Items.Select(k => $"[{k.HotKey}]\t[{k.ProcessName}]\t触发了 {k.TriggerCounter} 次")), "统计结果");
|
||||
}
|
||||
|
||||
#endregion 托盘图标管理
|
||||
|
||||
#region 开机自启动
|
||||
@ -309,5 +331,140 @@ namespace KeyGo
|
||||
}
|
||||
|
||||
#endregion 开机自启动
|
||||
|
||||
#region 拖拽
|
||||
|
||||
private void FLPHotKeys_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||
e.Effect = DragDropEffects.Link;
|
||||
else
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
|
||||
private void FLPHotKeys_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetData(DataFormats.FileDrop) is Array files && files.Length > 0)
|
||||
{
|
||||
var filepath = files.GetValue(0) as string;
|
||||
var frm = new FormHotKey
|
||||
{
|
||||
HotKeyItem = new HotKeyItem
|
||||
{
|
||||
StartupPath = filepath,
|
||||
}
|
||||
};
|
||||
if (frm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
AddHotKeyItem(frm.HotKeyItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 拖拽
|
||||
|
||||
#region 配置文件管理
|
||||
|
||||
private string ConfigToString(List<HotKeyItem> items)
|
||||
{
|
||||
return string.Join(Environment.NewLine, items.Select(item => $"{item.HotKey}|{item.ProcessName}|{item.StartupPath}"));
|
||||
}
|
||||
|
||||
private List<HotKeyItem> ParseConfig(string config)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(config))
|
||||
throw new ArgumentNullException(nameof(config));
|
||||
|
||||
return config.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(s =>
|
||||
{
|
||||
var strs = s.Split('|');
|
||||
if (strs.Length < 3)
|
||||
throw new Exception("数据格式不正确,无法解析");
|
||||
return new HotKeyItem
|
||||
{
|
||||
HotKey = strs[0],
|
||||
ProcessName = strs[1],
|
||||
StartupPath = strs[2],
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private void ImportConfig(string config)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(config))
|
||||
{
|
||||
MessageBox.Show("导入失败,数据为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var items = ParseConfig(config);
|
||||
foreach (var item in items)
|
||||
AddHotKeyItem(item, false);
|
||||
SaveHotKeyItems(_KeyGo);
|
||||
MessageBox.Show("导入完成", "提示");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "导入失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void TSMIExportConfig_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveFileDialog frm = new SaveFileDialog
|
||||
{
|
||||
Title = "请选择文件保存位置",
|
||||
Filter = "Config file (*.config)|*.config|All file (*.*)|*.*",
|
||||
FileName = "KeyGo_Hotkey.config",
|
||||
RestoreDirectory = true,
|
||||
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
||||
};
|
||||
if (frm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
using (StreamWriter writer = new StreamWriter(frm.OpenFile()))
|
||||
{
|
||||
writer.Write(ConfigToString(_KeyGo.Items));
|
||||
}
|
||||
if (MessageBox.Show("写入完成,是否打开目录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
Process.Start("Explorer", "/select,"+ frm.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void TSMIImportConfig_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog frm = new OpenFileDialog
|
||||
{
|
||||
Title = "请选择配置文件",
|
||||
Filter = "Config file (*.config)|*.config|All file (*.*)|*.*",
|
||||
RestoreDirectory = true,
|
||||
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
||||
};
|
||||
if (frm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string data;
|
||||
using (StreamReader reader = new StreamReader(frm.OpenFile()))
|
||||
{
|
||||
data = reader.ReadToEnd();
|
||||
}
|
||||
ImportConfig(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void TSMICopyConfig_Click(object sender, EventArgs e)
|
||||
{
|
||||
Clipboard.SetDataObject(ConfigToString(_KeyGo.Items), true);
|
||||
}
|
||||
|
||||
private void TSMIPasteConfig_Click(object sender, EventArgs e)
|
||||
{
|
||||
ImportConfig(Clipboard.GetText());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -253,14 +253,24 @@ namespace KeyGo
|
||||
/// 添加一个新热键
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// item
|
||||
/// or
|
||||
/// HotKey - 热键不能为空!
|
||||
/// </exception>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// 功能键不能为空!
|
||||
/// or
|
||||
/// 快捷键不能为空!
|
||||
/// </exception>
|
||||
public void AddHotKey(HotKeyItem item)
|
||||
{
|
||||
if (item is null)
|
||||
throw new ArgumentNullException(nameof(item));
|
||||
|
||||
Items.Add(item);
|
||||
if (item.Enabled)
|
||||
RegKey(item);
|
||||
Items.Add(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -272,10 +282,9 @@ namespace KeyGo
|
||||
if (item is null)
|
||||
throw new ArgumentNullException(nameof(item));
|
||||
|
||||
Items.Remove(item);
|
||||
|
||||
if (item.HotKeyID != 0)
|
||||
UnRegKey(item);
|
||||
Items.Remove(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -8,10 +8,11 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>KeyGo</RootNamespace>
|
||||
<AssemblyName>KeyGo</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
2
KeyGo/Properties/Resources.Designer.cs
generated
2
KeyGo/Properties/Resources.Designer.cs
generated
@ -19,7 +19,7 @@ namespace KeyGo.Properties {
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
29
KeyGo/Properties/Settings.Designer.cs
generated
29
KeyGo/Properties/Settings.Designer.cs
generated
@ -1,27 +1,24 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace KeyGo.Properties
|
||||
{
|
||||
namespace KeyGo.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user