Пример #1
0
        private bool RegisterHotkey(HotkeyInfo hotkeyInfo, bool save = false)
        {
            Hotkey hotkey = new Hotkey(hotkeyInfo, GetHandlerForm(hotkeyInfo));
            bool   registered;

            if (registered = hotkey.Register())
            {
                _hotkeys.Add(hotkey);
                if (save)
                {
                    SaveHotkeys();
                }
#if DEBUG
                System.Diagnostics.Debug.Print("{0}\t{1}", hotkey, registered ? "OK" : "Failed to Register");
#endif
            }
            return(registered);
        }
Пример #2
0
        public static HotkeyInfo ShowHotkeyDialog(HotkeyInfo initial = null)
        {
            HotkeyInfo         result = null;
            RegisterHotkeyForm registerHotkeyForm;

            if (initial != null)
            {
                registerHotkeyForm = new RegisterHotkeyForm(initial);
            }
            else
            {
                registerHotkeyForm = new RegisterHotkeyForm();
            }

            if (registerHotkeyForm.ShowDialog() == DialogResult.OK)
            {
                result = registerHotkeyForm.HotkeyInfoResult;
            }
            return(result);
        }
Пример #3
0
        public RegisterHotkeyForm(HotkeyInfo initial) : this()
        {
            var checkedModifiers = initial.Modifiers
                                   .ToString()
                                   .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                                   .Select(strEnum =>
            {
                KeyModifier outEnum;
                Enum.TryParse(strEnum, out outEnum);
                return(outEnum);
            });

            foreach (var checkBox in _modifiersGroup.Controls.OfType <CheckBox>())
            {
                if (checkedModifiers.Contains((KeyModifier)checkBox.Tag))
                {
                    checkBox.Checked = true;
                }
            }

            _keyCombo.SelectedItem      = initial.Key;
            _functionCombo.SelectedItem = initial.Function;
        }