想做一个程序的热键像QQ一样呼出的热键。C#有没有这个功能。谢谢各位大哥

解决方案 »

  1.   

    有的.在KeyPress事件里写,判断所按下的键的KeyChar,然后再做相应的处理
      

  2.   

    KeyPress 只能在前台 的,当我在其他窗口按的时候就不起作用了。
      

  3.   

    please search : c# RegistHotKeyC#中调用API函数RegisterHotKey注册多个系统热键
      

  4.   

    winForm程序或许有.
    b/s的就可能没有了.
      

  5.   

    调用windowsAPI 处理消息吧。
      

  6.   

    在看在看 逍遥兄 的 
    不过看不太懂。我想知道。这个枚举是固定的还是自己定义的,如果是固定的那又是根据什么来设置的。因为如果我要改用其他的键可能就不知道是什么枚举了         None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            Windows = 8
      

  7.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices; // 需要加上这句话namespace HotKey
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        [DllImport("user32")]
            public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);//注册热键
            [DllImport("user32")]
            public static extern bool UnregisterHotKey(IntPtr hWnd, int id);//解除热键                protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case 0x0312:    //这个是window消息定义的   注册的热键消息
                        if (m.WParam.ToString().Equals("1"))  //这是我们注册的那個热键1
                        {
                            MessageBox.Show("CTRL+ALT+T:QQ窗体弹出来了~");
                        }
                        if (m.WParam.ToString().Equals("2"))  //这是我们注册的那個热键1
                        {
                            MessageBox.Show("ALT+T:QQ窗体弹出来了~");
                        }  
                        break;
                }
                base.WndProc(ref m);
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                // 第三个参数的试用方法:
                // 4:shift
                // 2:ctrl
                // 1:alt
                // so,ctrl+alt = 2+1 = 3            /*
                 * 第一个参数默认,第二个参数为标识符,第三个参数方法见上面的注释
                 */
                RegisterHotKey(Handle, 1, 3, Keys.T);//注册按键,CTRL+ALT+T            RegisterHotKey(Handle, 2, 1, Keys.T);// ALT+T
            }
        }
    }