C#窗口全局快捷键程序集NHotkey
By
admin
at 2023-02-03 • 0人收藏 • 549人看过
using System; using System.Windows.Forms; using NHotkey; using NHotkey.WindowsForms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); HotkeyManager.Current.AddOrReplace("Increment", /*Keys.Control | Keys.Alt |*/Keys.A, OnIncrement); HotkeyManager.Current.AddOrReplace("Decrement", /*Keys.Control | Keys.Alt |*/ Keys.B, OnDecrement); } private void OnDecrement(object sender, HotkeyEventArgs e) { Console.WriteLine("BBBOnDecrement, on \n "); e.Handled = true; } private void OnIncrement(object sender, HotkeyEventArgs e) { Console.WriteLine("AAAOnIncrement, on \n "); e.Handled = true; } } }
private void OnIncrementOrDecrement(object sender, HotkeyEventArgs e) { switch (e.Name) { case "Increment": Value++; break; case "Decrement": Value--; break; } e.Handled = true; }
该方法是全局快捷键, 注册后无论窗口焦点在不在都会触发, 关闭窗口后失效.
官方地址:
https://github.com/thomaslevesque/NHotkey
1 个回复 | 最后更新于 2023-02-03
登录后方可回帖
如果需要窗口快捷键, 那么利用重载系统函数的办法能够更好的操作:
然后自己在重载里各种配置就好
如下: