Sage.WindowsHotKey 1.0.0

dotnet add package Sage.WindowsHotKey --version 1.0.0
                    
NuGet\Install-Package Sage.WindowsHotKey -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sage.WindowsHotKey" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sage.WindowsHotKey" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Sage.WindowsHotKey" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sage.WindowsHotKey --version 1.0.0
                    
#r "nuget: Sage.WindowsHotKey, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sage.WindowsHotKey@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sage.WindowsHotKey&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Sage.WindowsHotKey&version=1.0.0
                    
Install as a Cake Tool

Sage.WindowsHotKey

简介

Sage.WindowsHotKey 提供了 Windows 全局热键的注册和管理功能。

主要特性

  • 支持全局热键注册和注销
  • 热键事件处理
  • 热键状态查询
  • 完全兼容 AOT 编译

使用示例

using Sage.WindowsHotKey;
using Sage.WindowsHotKey.Models;
using System.Windows.Forms;

public partial class MainForm : Form
{
    private readonly HotKeyManager _hotKeyManager;

    public MainForm()
    {
        InitializeComponent();
        _hotKeyManager = new HotKeyManager(this);
        
        // 注册热键
        var result = _hotKeyManager.RegisterHotKey(
            "CaptureScreen",
            Keys.PrintScreen,
            HotKeyModifiers.Control,
            "截取屏幕");
            
        if (result.Success)
        {
            Console.WriteLine($"热键注册成功:{result.
            HotKey.Name}");
        }
        
        // 订阅热键事件
        _hotKeyManager.HotKeyPressed += 
        OnHotKeyPressed;
    }
    
    private void OnHotKeyPressed(object sender, 
    HotKeyEventArgs e)
    {
        if (e.HotKey.Name == "CaptureScreen")
        {
            Console.WriteLine("截图热键被按下");
            // 执行截图操作
        }
    }
    
    protected override void WndProc(ref Message m)
    {
        // 必须调用以处理热键消息
        _hotKeyManager.ProcessHotKeyMessage(ref m);
        base.WndProc(ref m);
    }
    
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            _hotKeyManager.Dispose();
        }
        base.Dispose(disposing);
    }
}

许可证

版权所有 © 2025 甲壳虫科技 团队。

贡献

欢迎提交问题和功能请求。 QQ Group: 1054304346

作者

甲壳虫科技

Product Compatible and additional computed target framework versions.
.NET net9.0-windows7.0 is compatible.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 113 7/16/2025