zoukankan      html  css  js  c++  java
  • c# 注册热键功能

    using System.Runtime.InteropServices;

    //注册热键的api

    [DllImport("user32")]

    public static extern bool RegisterHotKey(IntPtr hWnd,int id,uint control,Keys vk );

    //解除注册热键的api

    [DllImport("user32")]
    public static extern bool UnregisterHotKey(IntPtr hWnd, int id);


    private void Form2_Load1(object sender, System.EventArgs e)
    {
                RegisterHotKey(this.Handle,888,2,Keys.A);
                //handle:这个窗体的handle   888:这个热键的标志id    2:crtl鍵   A: a鍵
    }

    private void Form2_Load1(object sender, System.EventArgs e)
    {
                 UnregisterHotKey(this.Handle,888);    
                //handle:这个窗体的handle   888:上面那个热键的标志id  
    }

    protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case 0x0312:    //这个是window消息定义的   注册的热键消息
                        if(m.WParam.ToString().Equals("888"))  //如果是我们注册的那個热键
                            MessageBox.Show("你按了ctrl+a");
                        break;
                }            
                base.WndProc (ref m);
            }

    None = 0,Alt = 1,crtl= 2,   Shift = 4,Windows = 8

    这是热键的定义  alt+crtl是3  直接相加就可以了


    如果用sendmessagea这個api  就是

    SendMessage(this.Handle,WM_SETHOTKEY,0x45a, 0)

    //WM_SETHOTKEY 是 0x32
    //0x45a    高字节是contrl键  低字节是a b c d   所以5a是z的ascii   4是alt  也就是alt+z

  • 相关阅读:
    cv2.matchTemplate图片匹配
    pytorch 安装坑
    滑动轨迹函数记录
    selenium chrome开发者
    tp5 json()与json_encode()
    where 查询
    tp5.1 Class not found
    978. Longest Turbulent Subarray
    1004. Max Consecutive Ones III
    424. Longest Repeating Character Replacement
  • 原文地址:https://www.cnblogs.com/zhahost/p/1221482.html
Copyright © 2011-2022 走看看