Пример #1
0
        /// <summary>Specifies the entire information about this HotKey.
        /// </summary>
        /// <returns>A string representation of the information.</returns>
        public string FullInfo()
        {
            string bhot = "";
            string chot = "";

            bhot = HotKeyShared.CombineShortcut(BaseModifier, BaseKey);
            chot = HotKeyShared.CombineShortcut(ChordModifier, ChordKey);

            return(String.Format("{0} ; {1} ; {2} ; {3}Enabled ; ChordHotKey", Name, bhot, chot, Enabled ? "" : "Not "));
        }
Пример #2
0
        /// <summary>Checks if a hotkey has already been registered as a Local or Global HotKey.
        /// </summary>
        /// <param name="shortcut">The hotkey string to check.</param>
        /// <param name="ToCheck">The HotKey type to check.</param>
        /// <returns>True if the HotKey is already registered, false otherwise.</returns>
        public bool HotKeyExists(string shortcut, CheckKey ToCheck)
        {
            Keys         Key      = (Keys)HotKeyShared.ParseShortcut(shortcut).GetValue(1);
            ModifierKeys Modifier = (ModifierKeys)HotKeyShared.ParseShortcut(shortcut).GetValue(0);

            switch (ToCheck)
            {
            case CheckKey.GlobalHotKey:
                return(GlobalHotKeyContainer.Exists
                       (
                           delegate(GlobalHotKey g)
                {
                    return (g.Key == Key && g.Modifier == Modifier);
                }
                       ));

            case CheckKey.LocalHotKey:     //Check if a LocalHotkey already exists with the same name and modifier or a chord has it's base key set.
                return(LocalHotKeyContainer.Exists
                       (
                           delegate(LocalHotKey l)
                {
                    return (l.Key == Key && l.Modifier == Modifier);
                }
                       )
                       | //Or.
                       ChordHotKeyContainer.Exists
                       (
                           delegate(ChordHotKey c)
                {
                    return (c.BaseKey == Key && c.BaseModifier == Modifier);
                }));

            case CheckKey.Both:
                return(HotKeyExists(shortcut, CheckKey.GlobalHotKey) ^ HotKeyExists(shortcut, CheckKey.LocalHotKey));
            }
            return(false);
        }
Пример #3
0
        void HotKeyControl_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard();
            bool AltPressed     = UserKeyBoard.AltKeyDown;
            bool ControlPressed = UserKeyBoard.CtrlKeyDown;
            bool ShiftPressed   = UserKeyBoard.ShiftKeyDown;

            ModifierKeys LocalModifier = ModifierKeys.None;

            if (AltPressed)
            {
                LocalModifier = ModifierKeys.Alt;
            }
            if (ControlPressed)
            {
                LocalModifier |= ModifierKeys.Control;
            }
            if (ShiftPressed)
            {
                LocalModifier |= ModifierKeys.Shift;
            }

            switch (e.Key)
            {
            case Key.Back:
                this.Text = Keys.None.ToString();
                e.Handled = true;
                break;

            case Key.Space:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Space) : Keys.None.ToString();
                e.Handled = true;
                break;

            case Key.Delete:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Delete) : Keys.None.ToString();
                e.Handled = true;
                break;

            case Key.Home:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Home) : Keys.None.ToString();
                e.Handled = true;
                break;

            case Key.PageUp:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.PageUp) : Keys.None.ToString();
                e.Handled = true;
                break;

            case Key.Next:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Next) : Keys.None.ToString();
                e.Handled = true;
                break;

            case Key.End:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.End) : Keys.None.ToString();
                break;

            case Key.Up:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Up) : Keys.None.ToString();
                break;

            case Key.Down:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Down) : Keys.None.ToString();
                break;

            case Key.Right:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Right) : Keys.None.ToString();
                break;

            case Key.Left:
                this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Left) : Keys.None.ToString();
                break;
            }
        }
Пример #4
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            try
            {
                Keys KeyPressed = (Keys)wParam;

                Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard();
                bool AltPressed     = UserKeyBoard.AltKeyDown;
                bool ControlPressed = UserKeyBoard.CtrlKeyDown;
                bool ShiftPressed   = UserKeyBoard.ShiftKeyDown;

                ModifierKeys LocalModifier = ModifierKeys.None;
                if (AltPressed)
                {
                    LocalModifier = ModifierKeys.Alt;
                }
                if (ControlPressed)
                {
                    LocalModifier |= ModifierKeys.Control;
                }
                if (ShiftPressed)
                {
                    LocalModifier |= ModifierKeys.Shift;
                }

                switch ((KeyboardMessages)msg)
                {
                case KeyboardMessages.WmSyskeydown:
                case KeyboardMessages.WmKeydown:
                    switch (KeyPressed)
                    {
                    case Keys.Control:
                    case Keys.ControlKey:
                    case Keys.LControlKey:
                    case Keys.RControlKey:
                    case Keys.Shift:
                    case Keys.ShiftKey:
                    case Keys.LShiftKey:
                    case Keys.RShiftKey:
                    case Keys.Alt:
                    case Keys.Menu:
                    case Keys.LMenu:
                    case Keys.RMenu:
                    case Keys.LWin:
                        return(IntPtr.Zero);

                        //case Keys.Back:
                        //    this.Text = Keys.None.ToString();
                        //    return IntPtr.Zero;
                    }

                    if (LocalModifier != ModifierKeys.None)
                    {
                        this.Text = HotKeyShared.CombineShortcut(LocalModifier, KeyPressed);
                    }
                    else
                    {
                        if (ForceModifiers)
                        {
                            this.Text = Keys.None.ToString();
                            MessageBox.Show("You have to specify a modifier like 'Control', 'Alt' or 'Shift'");
                        }
                        else
                        {
                            this.Text = KeyPressed.ToString();
                        }
                    }
                    return(IntPtr.Zero);;

                case KeyboardMessages.WmSyskeyup:
                case KeyboardMessages.WmKeyup:
                    if (!String.IsNullOrEmpty(Text.Trim()) || this.Text != Keys.None.ToString())
                    {
                        if (HotKeyIsSetEvent != null)
                        {
                            var e = new HotKeyIsSetEventArgs(HotKeyIsSetEvent, UserKey, UserModifier);
                            base.RaiseEvent(e);
                            if (e.Cancel)
                            {
                                this.Text = Keys.None.ToString();
                            }
                        }
                    }
                    return(IntPtr.Zero);
                }
            }
            catch (OverflowException) { }

            return(IntPtr.Zero);
        }
Пример #5
0
 /// <summary>Information about this Hotkey.
 /// </summary>
 /// <returns>The properties of the hotkey.</returns>
 public string FullInfo()
 {
     return(string.Format("{0} ; {1} ; {2} ; {3}Enabled ; LocalHotKey", Name, HotKeyShared.CombineShortcut(Modifier, Key), WhenToRaise, Enabled ? "" : "Not "));
 }
Пример #6
0
 /// <summary>Specifies the Chord information of this HotKey.
 /// </summary>
 /// <returns>A string representation of the information.</returns>
 public string ChordInfo()
 {
     return(HotKeyShared.CombineShortcut(ChordModifier, ChordKey));
 }
Пример #7
0
 /// <summary>Specifies the base information of this HotKey.
 /// </summary>
 /// <returns>A string representation of the information.</returns>
 public string BaseInfo()
 {
     return(HotKeyShared.CombineShortcut(BaseModifier, BaseKey));
 }
Пример #8
0
 /// <summary>Checks if a hotkey has already been registered as a Local or Global HotKey.
 /// </summary>
 /// <param name="key">The key of the HotKey.</param>
 /// <param name="modifier">The modifier of the HotKey.</param>
 /// <param name="ToCheck">The HotKey type to check.</param>
 /// <returns>True if the HotKey is already registered, false otherwise.</returns>
 public bool HotKeyExists(Keys key, ModifierKeys modifier, CheckKey ToCheck)
 {
     return(HotKeyExists(HotKeyShared.CombineShortcut(modifier, key), ToCheck));
 }