日期:2011-06-12  浏览次数:20530 次

 以一个Form程序为例

public class Form1 : Form

{
            private void Form1_Load(object sender, System.EventArgs e)
            {
                        SetHotKey(false, false, false, true, Keys.Right, 100); // 设置多个热键
                        SetHotKey(false, false, false, true, Keys.Space, 101);
                        SetHotKey(false, false, false, true, Keys.Up, 102);
                        SetHotKey(false, false, false, true, Keys.Down, 103);
            }
            
            private bool key_Ctrl = false;
            private bool key_Shift = false;
            private bool key_Alt = false;
            private bool key_Windows = false;
            private Keys   key_other;

            public void SetHotKey(bool bCtrl,bool bShift,bool bAlt,bool  bWindows,Keys nowKey,int keyId)
            {
                  try
                  {
                        this.key_Alt = bAlt;
                        this.key_Ctrl = bCtrl;
                        this.key_Shift = bShift;
                        this.key_Windows = bWindows;
                        this.key_other = nowKey;
           
                        WinHotKey.KeyModifiers modifier = WinHotKey.KeyModifiers.None;
           
                        if( this.key_Ctrl )
                              modifier |= WinHotKey.KeyModifiers.Control;
                        if(this.key_Alt )
       &nbs