winform注册全局热键ALT+R快捷键呼出

winform csharp 文章 2023-02-15 09:44 724 0 全屏看文

AI助手支持GPT4.0

winform注册全局热键ALT+R快捷键呼出,不过在win10下貌似没生效,很奇怪。

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public partial class Form1 : Form
{
    // 导入 user32.dll 库中的 RegisterHotKey 和 UnregisterHotKey 函数
    [DllImport("user32.dll")]
    private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
    [DllImport("user32.dll")]
    private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

    // 定义热键 ID
    private const int HOTKEY_ID = 1;

    public Form1()
    {
        InitializeComponent();

        // 注册全局热键
        RegisterHotKey(this.Handle, HOTKEY_ID, (int)Modifiers.Alt, Keys.R.GetHashCode());
    }

    protected override void WndProc(ref Message m)
    {
        // 捕获 WM_HOTKEY 消息
        if (m.Msg == 0x0312 && m.WParam.ToInt32() == HOTKEY_ID)
        {
            // 处理热键事件
            if (this.Visible)
            {
                this.Hide();
            }
            else
            {
                this.Show();
            }
        }

        base.WndProc(ref m);
    }

    protected override void Dispose(bool disposing)
    {
        // 注销全局热键
        UnregisterHotKey(this.Handle, HOTKEY_ID);

        base.Dispose(disposing);
    }
}


-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
winform支持回车键调用方法。
winform判断chatGPTFilePath文件是否存在,如果不存在则创建文件和文件的父目录们
winform执行dos命令在textarea里实时输出
winform注册全局热键ALT+R快捷键呼出
加密混淆软件 net reactor的选项解释
随便看看
怎么添加小程序支付功能? 4516
教育科技公司申请微信支付被拒绝? 4798
微信公众号免300认证教程 5892
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 5299
小程序广告组件通过审核,但是小程序内没有显示广告? 5067
企业微信通讯录账号被管理员误/恶意删除,怎么办? 9568
问题? 9048
如何快速搭建抽奖助手小程序(无需代码知识) 6177
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 7472
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 6793