中文 | English
用优雅的方式构建WPF热键功能,支持全局/本地热键注册、可视化控件、源码生成器等特性

| 版本 |
类型 |
目标框架 |
特性 |
| 2.4.0 |
LTS |
.NET 6 |
非源码生成器 |
| 3.0.0 |
LTS |
.NET 5 / .NET Framework 4.7.1 |
基础功能 |
| 4.0.0 |
LTS |
.NET 5 / .NET Framework 4.6.2 |
统一API |
- 统一API - 跨框架一致的操作体验
- 增强注销 - 返回成功注销的热键数量
- 源码生成器 - 支持.NET Framework(需手动配置)
- 文档升级 - 新增函数原型速查表
// 全局热键(任意窗口生效)
GlobalHotKey.Register(
VirtualModifiers.Ctrl | VirtualModifiers.Alt,
VirtualKeys.F1,
(sender, e) => MessageBox.Show("全局热键触发!")
);
// 本地热键(指定控件生效)
LocalHotKey.Register(
textBox1,
new[] { Key.LeftCtrl, Key.K, Key.D },
(sender, e) => textBox1.Text = "Ctrl+K+D 已触发"
);
- 创建自定义控件(自动生成热键逻辑)
[HotKeyComponent]
public partial class HotKeyBox : UserControl
{
// 控件交互逻辑...
}
- XAML绑定热键属性
<TextBox KeyDown="OnHotKeyReceived"
Text="{Binding HotkeyText, RelativeSource={RelativeSource AncestorType=local:HotKeyBox}}"/>
| 方法 |
说明 |
Awake() |
初始化热键系统 |
Register(modifiers, keys) |
注册全局热键 |
Unregister(modifiers, keys) |
注销全局热键 |
Dispose() |
释放所有热键资源 |
| 方法 |
说明 |
Register(target, keys) |
注册控件级热键 |
Unregister(target) |
注销控件所有热键 |
RegisterMainWindow(keys) |
注册主窗口级热键 |
UnregisterMainWindow() |
注销主窗口所有热键 |
查看完整函数原型与使用指南
Elegant hotkey implementation for WPF, featuring global/local registration, visual controls, and source generators.

| Version |
Type |
Target Frameworks |
Features |
| 2.4.0 |
LTS |
.NET 6 |
Non-SourceGen |
| 3.0.0 |
LTS |
.NET 5 / .NET Framework 4.7.1 |
Basic Features |
| 4.0.0 |
LTS |
.NET 5 / .NET Framework 4.6.2 |
Unified API |
- Unified API - Consistent cross-framework experience
- Enhanced Unregister - Returns success count
- Source Generator - .NET Framework support (manual config)
- Documentation - Added function prototypes quick reference
// Global hotkey (works system-wide)
GlobalHotKey.Register(
VirtualModifiers.Ctrl | VirtualModifiers.Alt,
VirtualKeys.F1,
(sender, e) => MessageBox.Show("Global Hotkey Triggered!")
);
// Local hotkey (control-specific)
LocalHotKey.Register(
textBox1,
new[] { Key.LeftCtrl, Key.K, Key.D },
(sender, e) => textBox1.Text = "Ctrl+K+D Activated"
);
- Create custom control (auto-generated logic)
[HotKeyComponent]
public partial class HotKeyBox : UserControl
{
// Control interactions...
}
- XAML Data Binding
<TextBox KeyDown="OnHotKeyReceived"
Text="{Binding HotkeyText, RelativeSource={RelativeSource AncestorType=local:HotKeyBox}}"/>
| Method |
Description |
Awake() |
Initialize hotkey system |
Register(modifiers, keys) |
Register global hotkey |
Unregister(modifiers, keys) |
Unregister global hotkey |
Dispose() |
Release all hotkey resources |
| Method |
Description |
Register(target, keys) |
Register control-level hotkey |
Unregister(target) |
Unregister all control hotkeys |
RegisterMainWindow(keys) |
Register mainwindow-level hotkeys |
UnregisterMainWindow() |
Clear main window hotkeys |
View Complete API Reference