示例#1
0
        private Tuple <HotKey.KeyModifiers, int> GetKeysFormString(string a, string b, string curSet)
        {
            HotKey.KeyModifiers A = HotKey.KeyModifiers.None;
            int B = 0;

            try
            {
                A = (HotKey.KeyModifiers)Enum.Parse(typeof(HotKey.KeyModifiers), a);
                B = (int)Enum.Parse(typeof(System.Windows.Forms.Keys), b);
            }
            catch { }
            var result = new Tuple <HotKey.KeyModifiers, int>(A, B);

            PropertyInfo[] propertys = SettingHelp.Settings.GetType().GetProperties();
            foreach (PropertyInfo p in propertys)                                               //找到热键类属性,查找是否有冲突的热键设置
            {
                if (p.PropertyType.Equals(typeof(Tuple <HotKey.KeyModifiers, int>)))            //先判断是热键类设置
                {
                    var v = (Tuple <HotKey.KeyModifiers, int>)p.GetValue(SettingHelp.Settings); //取出设置的值
                    if (Equals(result, v) && p.Name != curSet)                                  //防止没有变化的修改提示冲突
                    {
                        Message("当前热键设置冲突,可能导致部分热键失效,请重新设置");
                        break;
                    }
                }
            }
            return(result);
        }
示例#2
0
文件: MainWindow .cs 项目: qt06/wx4b
 public void RegisterHotkey()
 {
     string[] sa = Settings.Default.Hotkey.Split(new char[] { '+' });
     if (sa.Length >= 2)
     {
         string[]            ms = sa[0].Trim().Split(new Char[] { ',' });
         HotKey.KeyModifiers km = HotKey.KeyModifiers.None;
         for (int i = 0; i < ms.Length; i++)
         {
             if (!string.IsNullOrEmpty(ms[i].Trim()))
             {
                 try
                 {
                     HotKey.KeyModifiers k = (HotKey.KeyModifiers)Enum.Parse(typeof(HotKey.KeyModifiers), ms[i].Trim());
                     km = km | k;
                 }
                 catch (Exception)
                 {
                     //throw;
                 }
             }
         }
         try
         {
             Keys vk = (Keys)Enum.Parse(typeof(Keys), sa[1].Trim());
             HotKey.RegisterHotKey(this.Handle, 12345, km, vk);
         }
         catch (Exception)
         {
             //throw;
         }
     }
 }
        public HotKey RegisterHotKey(Keys key, HotKey.KeyModifiers modifiers)
        {
            HotKey hk = new HotKey(this.Handle);

            hk.KeyModifier    = modifiers;
            hk.Key            = key;
            hk.HotKeyPressed += new KeyEventHandler(KeyHandler);
            if (!hk.isKeyRegistered)
            {
                hk.Dispose();
                hk = null;
            }
            return(hk);
        }