Beispiel #1
0
        private bool TryRegHotkey(TextBox tb)
        {
            var hotkey = HotKeys.Str2HotKey(tb.Text);

            if (hotkey == null)
            {
                MessageBox.Show(string.Format(I18N.GetString("Cannot parse hotkey: {0}"), tb.Text));
                tb.Clear();
                return(false);
            }

            HotKeys.HotKeyCallBackHandler callBack;
            Label lb;

            PrepareForHotkey(tb, out callBack, out lb);

            UnregPrevHotkey(callBack);

            // try to register keys
            // if already registered by other progs
            // notify to change

            // use the corresponding label color to indicate
            // reg result.
            // Green: not occupied by others and operation succeed
            // Yellow: already registered by other program and need action: disable by clear the content
            //         or change to another one
            // Transparent without color: first run or empty config

            bool regResult = HotKeys.Regist(hotkey, callBack);

            lb.BackColor = regResult ? Color.Green : Color.Yellow;
            return(regResult);
        }
        /// <summary>
        /// 注册热键
        /// </summary>
        private void Func_hotKeys_reg()
        {
            //注册Ctrl + Shift + Alt + Left 快捷键
            //注册Ctrl + Shift + Alt + Right 快捷键
            bool is_leftDesktop  = false;           //默认为失败
            bool is_rightDesktop = false;           //默认为失败

            is_leftDesktop  = h.Regist(Handle, HotKeys.keys_Control + HotKeys.keys_Shift, Keys.Subtract, Func_left_callBack);
            is_rightDesktop = h.Regist(Handle, HotKeys.keys_Control + HotKeys.keys_Shift, Keys.Add, Func_right_callBack);
            if (is_leftDesktop && is_rightDesktop)
            {
                Console.WriteLine("注册热键成功");
            }
            else
            {
                Console.WriteLine("注册热键失败");
            }
        }
Beispiel #3
0
 private void btnRegist_Click(object sender, EventArgs e)
 {
     //这里注册了Ctrl+Alt+E 快捷键
     h.Regist(this.Handle, (int)HotKeys.HotkeyModifiers.Alt, Keys.Q, CallBack);
     // MessageBox.Show ("注册成功");
 }