c#注册全局热键

来源:互联网 发布:做淘宝猝死 编辑:程序博客网 时间:2024/05/16 01:57

[DllImport("user32.dll")]

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

 [DllImport("user32.dll")]

 public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

 

 

 RegisterHotKey(this.Handle, 255,1   , Keys.B);//注册快捷键alt+B   1为alt

UnregisterHotKey(this.Handle, 255);//注销

 

 

 

 protected override void WndProc(ref Message m)

        {

            switch (m.Msg)

            { 

               case  0x0312:

                   switch (m.WParam.ToInt32())

                    {

                        case 255:    /* 热键促发内容*/ break;

 

                    } break;

 

            }

            base.WndProc(ref m);

        }//接受消息

原创粉丝点击