Example #1
0
 public SelectAction(Hotkey hotkey)
 {
     InitializeComponent();
     _hotkey = hotkey;
     _actions = hotkey.Actions;
     _actionContainer = new ActionContainer();
 }
Example #2
0
        /// <summary>
        ///     Add a Global Hotkey
        /// </summary>
        /// <param name="hotkey">Hotkey</param>
        /// <returns>True on success</returns>
        public bool Add(Hotkey hotkey)
        {
            int id = 0;
            // Add hotkey to settings
            try
            {
                Settings.Default.HotKeys.Add(hotkey);
                Logger.Instance.WriteGlobal("Register hotkey: {0} - {1}+{2}", hotkey.Name,
                    hotkey.Modifier.ToString().Replace(", ", "+"), hotkey.Key);
                id = _keyboardHook.RegisterHotKey(hotkey.Modifier, hotkey.Key);
                hotkey.HookId = id;

                foreach (Action action in hotkey.Actions)
                {
                    Debug.WriteLine("Initialize Hotkey: {0} {1}", action.Name, action.Version);
                    ActionContainer.GetAction(action.Name, action.Version).OnInitialize(hotkey);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteGlobal("Failed to register hotkey with message: " + ex.Message);
                DebugHelper.Exception(ex);
            }
            return id >= 1;
        }
 public NewHotkey(Hotkey hotkey)
 {
     InitializeComponent();
     Text = "Edit Hotkey";
     textBox1.Text = hotkey.Name;
     textBox2.Text = string.Format("{0}+{1}", hotkey.Modifier.ToString().Replace(", ", "+"), hotkey.Key);
     HotkeyNew = hotkey;
 }
Example #4
0
        /// <summary>
        /// Binds a <see cref="Hotkey"/> to a <see cref="HotkeyCallback"/>.
        /// </summary>
        /// <exception cref="HotkeyAlreadyBoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public HotkeyCallback Bind(Hotkey hotkeyCombo)
        {
            if (hotkeyCombo == null)
                throw new ArgumentNullException("hotkeyCombo");

            HotkeyCallback callback = new HotkeyCallback();
            container.Add(hotkeyCombo, callback);
            RegisterHotkey(hotkeyCombo);

            return callback;
        }
Example #5
0
        public static void Register(IWin32Window owner, int id, Hotkey hotkey)
        {
            if(hotkey == null) return;

            uint modifiers = 0;
            if(hotkey.Alt) modifiers |= 0x0001;
            if(hotkey.Control) modifiers |= 0x0002;
            if(hotkey.Shift) modifiers |= 0x0004;

            RegisterHotKey(owner.Handle, id, modifiers, (uint) hotkey.KeyCode);
        }
Example #6
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Back)
            {
                Reset();
                return;
            }

            var converter = new HotkeyConverter();
            Hotkey = (Hotkey) converter.ConvertFrom(e.KeyData);
            RenderText();
        }
Example #7
0
        public HotkeyHandle Map(Hotkey hotkey, HotkeyHandler action)
        {
            var mapping = new HotkeyMapping {
                Hotkey = hotkey,
                Action = action,
                Id = Interlocked.Increment(ref _idCounter)
            };

            _agent.AddMapping(mapping);

            return HotkeyHandle.Create(() => _agent.RemoveMappingByHotkey(hotkey));
        }
Example #8
0
        private void mOkButton_Click(object sender, EventArgs e)
        {
            List<Hotkey> hotkeyList = new List<Hotkey>();

            for (int i = 0; i < _hotkeyControls.Count; i++)
            {
                Hotkey hotkey = new Hotkey(_hotkeyControls[i].HotkeyName, _hotkeyControls[i].HotkeyEnabled, _hotkeyControls[i].HotkeyKey);
                hotkeyList.Add(hotkey);
            }
            SmartVolManagerPackage.BgMusicManager.MuteFmConfig.Hotkeys = hotkeyList.ToArray();
            MuteFmConfigUtil.Save(SmartVolManagerPackage.BgMusicManager.MuteFmConfig);
            this.Close();
        }
Example #9
0
 ///<summary>
 ///  Call first
 ///</summary>
 public PathControl(PathProfile pathProfile)
 {
     InitializeComponent();
     DoubleBuffered = true;
     GraphView.BringToFront();
     _pathProfile = pathProfile;
     _pathLoadedThread = new Thread(LoadPath) {IsBackground = true};
     _pathLoadedThread.Start();
     if (LazySettings.SetupUseHotkeys)
     {
         _f7 = new Hotkey();
         _f7.KeyCode = Keys.F7;
         _f7.Windows = false;
         _f7.Pressed += delegate { AddSpot(); };
         try
         {
             if (!_f7.GetCanRegister(this))
             {
                 Logging.Write("Cannot register F7 as hotkey");
             }
             else
             {
                 _f7.Register(this);
             }
         }
         catch
         {
             Logging.Write("Cannot register F7 as hotkey");
         }
         _f8 = new Hotkey();
         _f8.KeyCode = Keys.F8;
         _f8.Windows = false;
         _f8.Pressed += delegate { AddNode(); };
         try
         {
             if (!_f8.GetCanRegister(this))
             {
                 Logging.Write("Cannot register F8 as hotkey");
             }
             else
             {
                 _f8.Register(this);
             }
         }
         catch
         {
             Logging.Write("Cannot register F8 as hotkey");
         }
     }
 }
Example #10
0
        /// <summary>
        /// Indicates whether a <see cref="Hotkey"/> has been bound already either 
        /// by this application or another application.
        /// </summary>
        /// <param name="hotkeyCombo">
        /// The <see cref="Hotkey"/> to evaluate.
        /// </param>
        /// <returns>
        /// <c>true</c> if the <see cref="Hotkey"/> has not been previously bound 
        /// and is available to be bound; otherwise, <c>false</c>.
        /// </returns>
        public bool IsHotkeyAlreadyBound(Hotkey hotkeyCombo)
        {
            bool successful =
                NativeMethods.RegisterHotKey(
                    hotkeyWindow.Handle,
                    hotkeyCombo.GetHashCode(),
                    (uint)hotkeyCombo.Modifier,
                    (uint)hotkeyCombo.Key);

            if (!successful)
                return true;

            NativeMethods.UnregisterHotKey(
                hotkeyWindow.Handle,
                hotkeyCombo.GetHashCode());

            return false;
        }
Example #11
0
        private void lbActions_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateHotkey();

            this.currentSelectedHotkey = lbActions.SelectedItem as Hotkey;

            txtHotkeyKeys.Text = this.currentSelectedHotkey.Shortcut;
        }
Example #12
0
 private void Start()
 {
     if (_firstTime)
     {
         LoadFirstTime();
         _firstTime = false;
     }
     if (File.Exists(OurDirectory + "\\Rotations\\" + RotationSettings.LoadedRotationManager + ".xml"))
     {
         RotationManagerController = new RotationManagerController();
         RotationManagerController.Load(OurDirectory + "\\Rotations\\" + RotationSettings.LoadedRotationManager +
                                        ".xml");
     }
     foreach (Rotation rotation in RotationManagerController.Rotations.Where(r => r.Active))
     {
         try
         {
             CheckBuffAndKeys(rotation.Rules.GetRules);
             var hotkey = new Hotkey();
             hotkey.Windows = rotation.Windows;
             hotkey.Shift = rotation.Shift;
             hotkey.Alt = rotation.Alt;
             hotkey.Control = rotation.Ctrl;
             Rotation rotation1 = rotation;
             hotkey.KeyCode = (Keys) RotationSettings.KeysList.FirstOrDefault(k => k.Text == rotation1.Key).Code;
             hotkey.Pressed += delegate { StartRotation(rotation1.Name); };
             if (!hotkey.GetCanRegister(this))
             {
                 Logging.Write("Cannot register {0} as hotkey", rotation.Key);
             }
             else
             {
                 hotkey.Register(this);
                 _hotKeys.Add(hotkey);
             }
         }
         catch
         {
             Logging.Write("Cannot register {0} as hotkey", rotation.Key);
         }
     }
 }
 public CatchHotkey(NewHotkey parent)
 {
     InitializeComponent();
     _parent = parent;
     _hotkey = parent.HotkeyNew;
 }
Example #14
0
        /// <summary>
        /// loads the HotKeys
        /// </summary>
        public void LoadHotKeys()
        {
            _hotkeyPlayPause = new Hotkey();
            _hotkeyStop = new Hotkey();
            _hotkeyNext = new Hotkey();
            _hotkeyPrev = new Hotkey();
            _hotkeyOverlay = new Hotkey();
            _hotkeyVolUp = new Hotkey();
            _hotkeyVolDown = new Hotkey();

            _hotkeyPlayPause.APlayControler = APlayControler;
            _hotkeyStop.APlayControler = APlayControler;
            _hotkeyNext.APlayControler = APlayControler;
            _hotkeyPrev.APlayControler = APlayControler;
            _hotkeyOverlay.APlayControler = APlayControler;
            _hotkeyVolUp.APlayControler = APlayControler;
            _hotkeyVolDown.APlayControler = APlayControler;

            _hotkeyPlayPause.SetHotkey(AConfiguration.HotkeyPlay.MAlt,
                                      AConfiguration.HotkeyPlay.MCtrl,
                                      AConfiguration.HotkeyPlay.MShift,
                                      false,
                                      AConfiguration.HotkeyPlay.HKey);

            _hotkeyNext.SetHotkey(AConfiguration.HotkeyNext.MAlt,
                                  AConfiguration.HotkeyNext.MCtrl,
                                  AConfiguration.HotkeyNext.MShift,
                                  false,
                                  AConfiguration.HotkeyNext.HKey);

            _hotkeyPrev.SetHotkey(AConfiguration.HotkeyPrev.MAlt,
                                      AConfiguration.HotkeyPrev.MCtrl,
                                      AConfiguration.HotkeyPrev.MShift,
                                      false,
                                      AConfiguration.HotkeyPrev.HKey);

            _hotkeyStop.SetHotkey(AConfiguration.HotkeyStop.MAlt,
                                      AConfiguration.HotkeyStop.MCtrl,
                                      AConfiguration.HotkeyStop.MShift,
                                      false,
                                      AConfiguration.HotkeyStop.HKey);

            _hotkeyOverlay.SetHotkey(AConfiguration.HotkeyOverlay.MAlt,
                                      AConfiguration.HotkeyOverlay.MCtrl,
                                      AConfiguration.HotkeyOverlay.MShift,
                                      false,
                                      AConfiguration.HotkeyOverlay.HKey);

            _hotkeyVolUp.SetHotkey(AConfiguration.HotkeyVolUp.MAlt,
                                      AConfiguration.HotkeyVolUp.MCtrl,
                                      AConfiguration.HotkeyVolUp.MShift,
                                      false,
                                      AConfiguration.HotkeyVolUp.HKey);

            _hotkeyVolDown.SetHotkey(AConfiguration.HotkeyVolDown.MAlt,
                                      AConfiguration.HotkeyVolDown.MCtrl,
                                      AConfiguration.HotkeyVolDown.MShift,
                                      false,
                                      AConfiguration.HotkeyVolDown.HKey);

            _hotkeyPlayPause.HotkeyPressed += HotkeyPlayPauseHotkeyPressed;
            _hotkeyStop.HotkeyPressed += HotkeyStopHotkeyPressed;
            _hotkeyNext.HotkeyPressed += HotkeyNextHotkeyPressed;
            _hotkeyPrev.HotkeyPressed += HotkeyPrevHotkeyPressed;
            _hotkeyOverlay.HotkeyPressed += HotkeyOverlayHotkeyPressed;
            _hotkeyVolUp.HotkeyPressed += HotkeyVolUpHotkeyPressed;
            _hotkeyVolDown.HotkeyPressed += HotkeyVolDownHotkeyPressed;

            try
            {
                _hotkeyPlayPause.Enabled = AConfiguration.HotkeyPlay.IsEnabled;
                _hotkeyStop.Enabled = AConfiguration.HotkeyStop.IsEnabled;
                _hotkeyNext.Enabled = AConfiguration.HotkeyNext.IsEnabled;
                _hotkeyPrev.Enabled = AConfiguration.HotkeyPrev.IsEnabled;
                _hotkeyOverlay.Enabled = AConfiguration.HotkeyOverlay.IsEnabled;
                _hotkeyVolUp.Enabled = AConfiguration.HotkeyVolUp.IsEnabled;
                _hotkeyVolDown.Enabled = AConfiguration.HotkeyVolDown.IsEnabled;
            }
            catch (HotkeyAlreadyInUseException)
            {
                //new Error("Could not register a hotkey (already in use).",_anAppHandle,false,this);
            }
        }
Example #15
0
        private void UnregisterHotkey(Hotkey hotkeyCombo)
        {
            bool successful =
                NativeMethods.UnregisterHotKey(
                    hotkeyWindow.Handle,
                    hotkeyCombo.GetHashCode());

            if (!successful)
                throw new HotkeyNotBoundException(Marshal.GetLastWin32Error());
        }
        private Hotkey SetHotKey(Keys keys, bool shift, bool control, bool alt, bool windows, ClipboardInfo selectedInfo)
        {
            try
            {
                int index = selectedInfo.INDEX;

                Hotkey hk = new Hotkey();
                hk.KeyCode = keys;
                hk.Shift = shift;
                hk.Control = control;
                hk.Alt = alt;
                hk.Windows = windows;

                switch (index)
                {
                    case 1:
                        hk.Pressed += new HandledEventHandler(hk_Pressed1);
                        break;
                    case 2:
                        hk.Pressed += new HandledEventHandler(hk_Pressed2);
                        break;
                    case 3:
                        hk.Pressed += new HandledEventHandler(hk_Pressed3);
                        break;
                    case 4:
                        hk.Pressed += new HandledEventHandler(hk_Pressed4);
                        break;
                    case 5:
                        hk.Pressed += new HandledEventHandler(hk_Pressed5);
                        break;
                    case 6:
                        hk.Pressed += new HandledEventHandler(hk_Pressed6);
                        break;
                    case 7:
                        hk.Pressed += new HandledEventHandler(hk_Pressed7);
                        break;
                    case 8:
                        hk.Pressed += new HandledEventHandler(hk_Pressed8);
                        break;
                    case 9:
                        hk.Pressed += new HandledEventHandler(hk_Pressed9);
                        break;
                    case 10:
                        hk.Pressed += new HandledEventHandler(hk_Pressed0);
                        break;
                    default:
                        break;
                }

                if (hk.GetCanRegister(this))
                {
                    hk.Register(this);
                    return hk;
                }

                return null;
            }
            catch (Exception ex)
            {
                ConsoleLib.ConsoleLib.WriteFormatted(ex.ToString() + "                    ", t);
                ConsoleLib.ConsoleLib.WriteLine(Environment.NewLine);
                return null;
            }
        }
Example #17
0
        private void RegisterHotkey(Hotkey hotkeyCombo)
        {
            bool successful =
                NativeMethods.RegisterHotKey(
                    hotkeyWindow.Handle,
                    hotkeyCombo.GetHashCode(),
                    (uint)hotkeyCombo.Modifier,
                    (uint)hotkeyCombo.Key);

            if (!successful)
                throw new Win32Exception(Marshal.GetLastWin32Error());
        }
Example #18
0
 private void RegisterHotKeys()
 {
     if (LazySettings.SetupUseHotkeys && !_hotKeysLoaded)
     {
         _f10 = new Hotkey();
         _f10.KeyCode = Keys.F10;
         _f10.Windows = false;
         _f10.Pressed += delegate { PauseBot(); };
         try
         {
             if (!_f10.GetCanRegister(this))
             {
                 Logging.Write("Cannot register F10 as hotkey");
             }
             else
             {
                 _f10.Register(this);
             }
         }
         catch
         {
             Logging.Write("Cannot register F10 as hotkey");
         }
         _f9 = new Hotkey();
         _f9.KeyCode = Keys.F9;
         _f9.Windows = false;
         _f9.Pressed += delegate { StartStopBotting(); };
         try
         {
             if (!_f9.GetCanRegister(this))
             {
                 Logging.Write("Cannot register F9 as hotkey");
             }
             else
             {
                 _f9.Register(this);
             }
         }
         catch
         {
             Logging.Write("Cannot register F9 as hotkey");
         }
         _hotKeysLoaded = true;
     }
 }
Example #19
0
 private void ButtonClearOnClick(object sender, EventArgs e)
 {
     Hotkey = null;
 }
Example #20
0
 public void RemoveMappingByHotkey(Hotkey hotkey)
 {
     for(var i = 0; i < _mappings.Count; i++) {
         if(_mappings[i].Hotkey == hotkey) {
             UnregisterMapping(_mappings[i]);
             _mappings.RemoveAt(i);
             break;
         }
     }
 }
 public void OnInitialize(Hotkey hotkey)
 {
     _hotkey = hotkey;
 }
Example #22
0
 /// <summary>
 /// Unbinds a previously bound <see cref="Hotkey"/>.
 /// </summary>
 /// <exception cref="HotkeyNotBoundException"></exception>
 /// <exception cref="ArgumentNullException"></exception>
 public void Unbind(Hotkey hotkeyCombo)
 {
     container.Remove(hotkeyCombo);
     UnregisterHotkey(hotkeyCombo);
 }
        public void Dispose()
        {
            if (null != _hotKey)
            {
                _hotKey.Dispose();
                _hotKey = null;
            }

            if (null != _notify)
            {
                _notify.Visible = false;
                _notify.Dispose();
                _notify = null;
            }
        }
Example #24
0
 public NewHotkey()
 {
     InitializeComponent();
     HotkeyNew = new Hotkey();
 }
Example #25
0
        // Récupération du raccourci de la hotkey
        private void registerHotkey(String raccourci, ref Hotkey hotkey, HotkeyMethodDelegate callback)
        {
            //Récupération et ajout des touches spéciales
            if (raccourci.Contains("CTRL"))
                hotkey.Control = true;
            if (raccourci.Contains("ALT"))
                hotkey.Alt = true;
            if (raccourci.Contains("MAJ"))
                hotkey.Shift = true;
            if (raccourci.Contains("WIN"))
                hotkey.Windows = true;

            //Récupération de la lettre
            String lettre = raccourci.Substring(raccourci.LastIndexOf("+") + 1);

            //Si lettre reconnue, ajout de celle-ci et enregistrement de la combinaison
            if (!Enum.IsDefined(typeof(Keys), lettre))
                afficheMessage("Hotkey", "Erreur de formatage du fichier de config");
            else
            {
                hotkey.KeyCode = (Keys)Enum.Parse(typeof(Keys), lettre, false);
                hotkey.Pressed += new System.ComponentModel.HandledEventHandler(callback);

                if (!hotkey.GetCanRegister(invokeControl))
                    afficheMessage("Hotkey", "Impossible d'enregistrer le raccourci");
                else
                    hotkey.Register(invokeControl);
            }
        }
        /// <summary>
        /// Activate CtrlCVMaster Shortcut Key
        /// </summary>
        public void ActivateShortcutKey(Keys keys, bool shift, bool control, bool alt, bool windows)
        {
            try
            {
                if (this.activateKey != null)
                    this.activateKey.Unregister();

                this.activateKey = new Hotkey();

                activateKey.KeyCode = keys;
                activateKey.Shift = shift;
                activateKey.Control = control;
                activateKey.Alt = alt;
                activateKey.Windows = windows;

                activateKey.Pressed += new HandledEventHandler(activateHk_Pressed);

                if (activateKey.GetCanRegister(this)) activateKey.Register(this);
            }
            catch (Exception ex)
            {
                ConsoleLib.ConsoleLib.WriteFormatted(ex.ToString() + "                    ", t);
                ConsoleLib.ConsoleLib.WriteLine(Environment.NewLine);
            }
        }
Example #27
0
 private void TextBoxOnKeyDown(object sender, KeyEventArgs e)
 {
     Hotkey = Hotkey.FromEventArgs(e);
     e.SuppressKeyPress = true;
 }
Example #28
0
 private void Reset()
 {
     Hotkey = new Hotkey(Modifiers.None, Keys.None);
     Text = "None";
 }
 /// <summary>
 ///     The internal method used to handle hotkeys that are pressed. This will subsequently call the Trigger method
 ///     provided the various checks and balances pass.
 /// </summary>
 private void KeyIsPressed(Hotkey hotKey)
 {
     // Ability Chain Check... placing a "Paws_" prefix ensures that no other registered hotkeys are messed with in the system.
     var abilityChain = AbilityChains.SingleOrDefault(o => "Paws_" + o.Name == hotKey.Name);
     if (abilityChain == null) return;
     if (StyxWoW.Me.Specialization == abilityChain.Specialization)
     {
         // We have a triggered Ability Chain
         Trigger(abilityChain);
     }
     else
     {
         Log.AbilityChain(
             string.Format(
                 "Hotkey detected, but your specialization must be {0} to trigger the {1} ability chain.",
                 abilityChain.Specialization.ToString().Replace("Druid", string.Empty), hotKey.Name));
     }
 }
Example #30
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            this.TopMost = false;
            //skinEngine1.SkinFile = Application.StartupPath + @"\MacOS.ssk";

            notifyIcon1.Visible = false;
            Hotkey hotkey;
            hotkey = new Hotkey(this.Handle);
            //定义快键(Ctrl + F1)
            Hotkey1 = hotkey.RegisterHotkey(System.Windows.Forms.Keys.F12, Hotkey.KeyFlags.MOD_CONTROL);
            hotkey.OnHotkey += new HotkeyEventHandler(OnHotkey);
        }