Example #1
0
        private void RegisterHotkey(Keys key, HandledEventHandler pressedWithCtrl, HandledEventHandler pressedAlone, Form placeholder)
        {
            //var normalHotkey = new Hotkey
            //{
            //    KeyCode = key,
            //    Control = false
            //};
            //normalHotkey.Pressed += pressedAlone;

            var withCtrlHotkey = new Hotkey
            {
                KeyCode = key,
                Control = true
            };

            withCtrlHotkey.Pressed += pressedWithCtrl;

            //if (!normalHotkey.GetCanRegister(placeholder) || !withCtrlHotkey.GetCanRegister(placeholder))
            if (!withCtrlHotkey.GetCanRegister(placeholder))
            {
                //TODO Send error
                Console.WriteLine(
                    "Whoops, looks like attempts to register will fail or throw an exception, show an error/visual user feedback");
                return;
            }
            //normalHotkey.Register(placeholder);
            withCtrlHotkey.Register(placeholder);

            //_registeredHotkeys.Add(normalHotkey);
            _registeredHotkeys.Add(withCtrlHotkey);
        }
Example #2
0
 public static void Raise(this HandledEventHandler handler, object sender, HandledEventArgs e)
 {
     if (handler != null)
     {
         handler(sender, e);
     }
 }
Example #3
0
        /**
         * Sets the user defined hotkeys
         * */
        public void setUserHotKey(Hotkey hotkey, String hotkeyString, HandledEventHandler onPressMethod)
        {
            String[] splitHotkeys = hotkeyString.Split('+');
            Keys     keycode;

            foreach (var keyString in splitHotkeys)
            {
                Enum.TryParse(keyString, out keycode);

                if (keycode == Keys.Control || keycode == Keys.ControlKey || keycode == Keys.LControlKey || keycode == Keys.RControlKey || keyString.ToUpper().Equals("CTRL"))
                {
                    hotkey.Control = true;
                }

                else if (keycode == Keys.Alt || keyString.ToUpper().Equals("ALT"))
                {
                    hotkey.Alt = true;
                }

                else if (keycode == Keys.Shift || keycode == Keys.ShiftKey || keycode == Keys.LShiftKey || keycode == Keys.RShiftKey || keyString.ToUpper().Equals("SHIFT"))
                {
                    hotkey.Shift = true;
                }

                else
                {
                    hotkey.KeyCode = keycode;
                }
            }

            hotkey.Pressed += onPressMethod;
            registerHotkey(hotkey);
        }
Example #4
0
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// handledeventhandler.BeginInvoke(sender, e, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this HandledEventHandler handledeventhandler, Object sender, HandledEventArgs e, AsyncCallback callback)
        {
            if (handledeventhandler == null)
            {
                throw new ArgumentNullException("handledeventhandler");
            }

            return(handledeventhandler.BeginInvoke(sender, e, callback, null));
        }
Example #5
0
 public static void Raise(this HandledEventHandler handler, object sender, out bool handled, bool defaultHandledValue = false)
 {
     handled = defaultHandledValue;
     if (handler != null)
     {
         HandledEventArgs e = new HandledEventArgs(handled);
         handler(sender, e);
         handled = e.Handled;
     }
 }
Example #6
0
        void HandCall(HandledEventHandler BeforeHandle, EventHandler AfterHandle, EventHandler callBack)
        {
            HandledEventArgs args = new HandledEventArgs();

            HandEvent(BeforeHandle, args);
            if (args.Handled == true)
            {
                return;
            }
            callBack(null, null);
            HandEvent(AfterHandle);
        }
Example #7
0
        void HandCallInit(HandledEventHandler BeforeHandle, EventHandler AfterHandle, EventHandler callBack)
        {
            HandledEventArgs args = new HandledEventArgs();

            HandEvent(BeforeHandle, args);
            if (args.Handled == true)
            {
                return;
            }
            View.BeginInit();
            callBack(null, null);
            View.EndInit();
            HandEvent(AfterHandle);
        }
Example #8
0
        public static void Register(Control control, KeyMod mod, Keys key, HandledEventHandler handler)
        {
            Hotkey hk = new Hotkey();

            hk.KeyCode  = key;
            hk.Alt      = mod.HasFlag(KeyMod.Alt);
            hk.Shift    = mod.HasFlag(KeyMod.Shift);
            hk.Control  = mod.HasFlag(KeyMod.Control);
            hk.Windows  = mod.HasFlag(KeyMod.Windows);
            hk.Pressed += handler;
            if (!hk.Register(control))
            {
                throw new Exception("Ошибочка вышла - не удалось зарегестрировать клавишу");
            }
        }
Example #9
0
        private void UpdateHotkey(HotkeySelectControl hkControl, Hotkey hotkey, HandledEventHandler hkEvent)
        {
            if (hkControl.Hotkey == Keys.None && hotkey.Registered)
            {
                hotkey.Pressed -= hkEvent;
                hotkey.Unregister();
                hotkey.KeyCode = Keys.None;
            }
            else
            {
                hotkey.KeyCode = hkControl.Hotkey;
                hotkey.Win     = hkControl.Win;
                hotkey.Ctrl    = hkControl.Ctrl;
                hotkey.Shift   = hkControl.Shift;
                hotkey.Alt     = hkControl.Alt;

                if (!hotkey.Registered && hotkey.KeyCode != Keys.None)
                {
                    hotkey.Register(this);
                    hotkey.Pressed += hkEvent;
                }
            }
        }
Example #10
0
        private void UpdateHotkey(HotkeySelectControl hkControl, Hotkey hotkey, HandledEventHandler hkEvent)
        {
            if (hkControl.Hotkey == Keys.None && hotkey.Registered)
            {
                hotkey.Pressed -= hkEvent;
                hotkey.Unregister();
                hotkey.KeyCode = Keys.None;
            }
            else
            {
                hotkey.KeyCode = hkControl.Hotkey;
                hotkey.Win = hkControl.Win;
                hotkey.Ctrl = hkControl.Ctrl;
                hotkey.Shift = hkControl.Shift;
                hotkey.Alt = hkControl.Alt;

                if (!hotkey.Registered && hotkey.KeyCode != Keys.None)
                {
                    hotkey.Register(this);
                    hotkey.Pressed += hkEvent;
                }
            }
        }
Example #11
0
        public static void Register(HotkeyType type, Control control, KeyMod mod, Keys key, HandledEventHandler handler)
        {
            Hotkey hk = new Hotkey();

            hk.WindowControl = control;
            hk.type          = type;
            hk.keyCode       = key;
            hk.alt           = mod.HasFlag(KeyMod.Alt);
            hk.shift         = mod.HasFlag(KeyMod.Shift);
            hk.control       = mod.HasFlag(KeyMod.Control);
            hk.windows       = mod.HasFlag(KeyMod.Windows);
            hk.Pressed      += handler;
            if (type == HotkeyType.System && !hk.Register())
            {
                throw new Exception("Ошибочка вышла - не удалось зарегестрировать клавишу");
            }
        }
Example #12
0
 void HandEvent(HandledEventHandler sender, HandledEventArgs e)
 {
     sender?.Invoke(View, e);
 }
Example #13
0
        private void RegisterHotkey(Keys keyCode, SettingValues.Modifiers modifiers, bool enabled, string desc, HandledEventHandler action)
        {
            if (!enabled || keyCode == Keys.None)
            {
                return;
            }

            Hotkey hk = new Hotkey()
            {
                Control = modifiers.Ctrl,
                Windows = modifiers.Win,
                Alt     = modifiers.Alt,
                Shift   = modifiers.Shift,
                KeyCode = keyCode
            };

            if (hotkeys.Any(h => h.ToString() == hk.ToString()))
            {
                MessageBox.Show($"Hotkey {hk} has multiple assignments and will not be registered for {desc}",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
            else
            {
                hk.Pressed += action;
                if (hk.Register(null))
                {
                    hotkeys.Add(hk);
                }
                else
                {
                    MessageBox.Show($"Failed to register hotkey {hk} for {desc}." + Environment.NewLine +
                                    Environment.NewLine +
                                    "It is probably being used by another program - often graphics software.",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
        }
Example #14
0
 private void RegisterMovePosHotkey(Keys keyCode, HandledEventHandler action)
 {
     RegisterHotkey(keyCode, settings.MovePosModifiers, settings.MovePosEnabled, "move by position", action);
 }
Example #15
0
 private void RegisterSwitchPosHotkey(Keys keyCode, HandledEventHandler action)
 {
     RegisterHotkey(keyCode, settings.SwitchPosModifiers, settings.SwitchPosEnabled, "switch by position", action);
 }
Example #16
0
 private void RegisterMoveDirHotkey(Keys keyCode, HandledEventHandler action)
 {
     RegisterHotkey(keyCode, settings.MoveDirModifiers, settings.MoveDirEnabled, "move by direction", action);
 }
 public static void HotkeyRegister(this Control control, KeyMod mod, Keys key, HandledEventHandler handler)
 {
     Hotkey.Register(HotkeyType.Control, control, mod, key, handler);
 }
Example #18
0
 public static void HotkeyRegister(this Control control, Keys key, HandledEventHandler handler)
 {
     Hotkey.Register(control, KeyMod.None, key, handler);
 }
Example #19
0
 private void RegisterSwitchDirHotkey(Keys keyCode, HandledEventHandler action)
 {
     RegisterHotkey(keyCode, settings.SwitchDirModifiers, settings.SwitchDirEnabled, "switch by direction", action);
 }