Ejemplo n.º 1
0
 private void RegisterHotKey(HotKey hotkey, HotKeyPressedEventHandler handler, ICollection <string> errors)
 {
     try
     {
         if (hotkey != null)
         {
             hotkey.HotKeyPressed += handler;
             hotkey.RegisterHotKey();
         }
     }
     catch (InvalidOperationException)
     {
     }
     catch (HotKeyAleadyInUseException e)
     {
         if (_settings.OverrideExistingHotKeys)
         {
             _hookHotKey.RegisterHotKey(hotkey.ModifierKeys, hotkey.Key, handler);
         }
         else
         {
             Trace.WriteLine("Error while registering hot key " + hotkey + "\n" + e);
             errors.Add("Error while registering hot key " + hotkey);
         }
     }
 }
Ejemplo n.º 2
0
        private void OnHotKeyPressed()
        {
            HotKeyPressedEventHandler pressedEventHandler = HotKeyPressed;

            if (pressedEventHandler == null)
            {
                return;
            }
            pressedEventHandler(this, new EventArgs());
        }
Ejemplo n.º 3
0
        public static HotKey RemoveHandler(this HotKey hotKey, HotKeyPressedEventHandler handler)
        {
            Contract.Ensures(Contract.Result <HotKey>() == hotKey);

            if (hotKey == null)
            {
                return(null);
            }

            hotKey.HotKeyPressed -= handler;
            return(hotKey);
        }
Ejemplo n.º 4
0
        public void RegisterHotKey(ModifierKeys modifierKeys, Keys key, HotKeyPressedEventHandler action)
        {
            HotKey hotKey = new HotKey(modifierKeys, key);

            hotKey.Action = action;
            if (_hotKeys.Contains(hotKey))
            {
                return; // TODO manage multiple handler
            }
            if (_hotKeys.Count == 0)
            {
                _hook.Install();
            }

            _hotKeys.Add(hotKey);
        }
Ejemplo n.º 5
0
        public void RegisterHotKey(ModifierKeys modifierKeys, Keys key, HotKeyPressedEventHandler action)
        {
            var hotKey = new HotKey(modifierKeys, key)
            {
                Action = action,
            };

            if (_hotKeys.Contains(hotKey))
            {
                return;
            }

            if (_hotKeys.Count == 0)
            {
                _hook.Install();
            }

            _hotKeys.Add(hotKey);
        }