Ejemplo n.º 1
0
 private HotKey(HotKeyFunction function, Keys key, HotModifierKeys modifiers)
     : this()
 {
     this.Function = function;
     this.Key = key;
     this.ModifierKeys = modifiers;
 }
Ejemplo n.º 2
0
 private void ModHotFlag(bool enabled, HotModifierKeys toggleEnum)
 {
     if (enabled)
         ModifierKeys |= toggleEnum;
     else
         ModifierKeys &= ~toggleEnum;
 }
Ejemplo n.º 3
0
 private HotKey(HotKeyFunction function, Keys key, HotModifierKeys modifiers)
     : this()
 {
     this.Function     = function;
     this.Key          = key;
     this.ModifierKeys = modifiers;
 }
Ejemplo n.º 4
0
 private void ModHotFlag(bool enabled, HotModifierKeys toggleEnum)
 {
     if (enabled)
     {
         ModifierKeys |= toggleEnum;
     }
     else
     {
         ModifierKeys &= ~toggleEnum;
     }
 }
Ejemplo n.º 5
0
        internal static void RegisterHotKey(NotifyIcon notifyIcon)
        {
            if (hotModifiers.HasFlag(Keys.Delete) || hotKey.HasFlag(Keys.Delete))
            {
                hotModifiers = Keys.None;
                hotKey       = Keys.None;
                Settings.Default.ModifierKeys = hotModifiers;
                Settings.Default.Key          = hotKey;
                Settings.Default.Save();
                notifyIcon.ShowBalloonTip(0, "Hot keys removed",
                                          "Hot keys have been successfully removed.", ToolTipIcon.Info);
                return;
            }

            HotModifierKeys modkeys = 0;

            if (hotModifiers.HasFlag(Keys.Control))
            {
                modkeys |= HotModifierKeys.Control;
            }
            if (hotModifiers.HasFlag(Keys.Alt))
            {
                modkeys |= HotModifierKeys.Alt;
            }
            if (hotModifiers.HasFlag(Keys.Shift))
            {
                modkeys |= HotModifierKeys.Shift;
            }
            if (modkeys == 0 || hotKey == 0)
            {
                return;
            }

            if (RegisterHotKey(handle, HotKeyID, (uint)modkeys, (uint)hotKey))
            {
                Settings.Default.ModifierKeys = hotModifiers;
                Settings.Default.Key          = hotKey;
                Settings.Default.Save();
                var modKeyStr = hotModifiers.ToString() == "0" ? "" : hotModifiers + " + ";
                notifyIcon.ShowBalloonTip(0, "AudioSwitch", string.Format(
                                              "Hot key {0}{1} has been successfully set.", modKeyStr, hotKey), ToolTipIcon.Info);
            }
            else
            {
                notifyIcon.ShowBalloonTip(0,
                                          "Hot key registration failed!",
                                          "This combination might be already in use. Please try again with a different combination.",
                                          ToolTipIcon.Error);
            }
        }
Ejemplo n.º 6
0
        private static string GetModifierString(HotModifierKeys keys, params HotModifierKeys[] modifiers)
        {
            StringBuilder returnValue = new StringBuilder();

            foreach (HotModifierKeys mod in modifiers)
            {
                if ((keys & mod) > 0)
                {
                    returnValue.AppendFormat("{0}+", (mod == HotModifierKeys.Control) ? "Ctrl" : mod.ToString());
                }
            }

            return(returnValue.ToString());
        }
Ejemplo n.º 7
0
        internal static short RegisterGlobalHotKey(short oldID, HotModifierKeys modifierKeys, Keys hotKey)
        {
            if (oldID != 0)
                UnregisterGlobalHotKey(oldID);

            try
            {
                var newID = HotKeyIDCounter++;
                if (!RegisterHotKey(Handle, newID, (uint)modifierKeys, (uint)hotKey))
                        return 0;
                return newID;
            }
            catch
            {
                return 0;
            }
        }
        internal static short RegisterGlobalHotKey(short oldId, HotModifierKeys modifierKeys, Keys hotKey)
        {
            if (oldId != 0)
                UnregisterGlobalHotKey(oldId);

            try
            {
                short newId = (short) Runtime.Instance.randomizer.Next(short.MinValue, short.MaxValue);
                if (
                    !RegisterHotKey(MainHandle, newId, (uint) modifierKeys,
                        (uint) hotKey))
                    return 0;
                return newId;
            }
            catch
            {
                return 0;
            }
        }
Ejemplo n.º 9
0
        internal static short RegisterGlobalHotKey(short oldID, HotModifierKeys modifierKeys, Keys hotKey)
        {
            if (oldID != 0)
            {
                UnregisterGlobalHotKey(oldID);
            }

            try
            {
                var newID = HotKeyIDCounter++;
                if (!RegisterHotKey(Handle, newID, (uint)modifierKeys, (uint)hotKey))
                {
                    return(0);
                }
                return(newID);
            }
            catch
            {
                return(0);
            }
        }
 internal static int  RegisterGlobalHotKey(int oldId, HotModifierKeys modifierKeys, Keys hotKey)
 {
     if (oldId != 0)
     {
         UnregisterGlobalHotKey(oldId);
     }
     try
     {
         int id = System.Threading.Interlocked.Increment(ref hotKeyId);
         // GlobalHotKeyApplicationId;
         if (!NativeMethods.RegisterHotKey(GlobalHotKeyManager.MainFormHandle, id, (uint)modifierKeys,
                                           (uint)hotKey))
         {
             return(0);
         }
         return(id);
     }
     catch
     {
         return(0);
     }
 }
Ejemplo n.º 11
0
            public void AddHotKey(Keys key, Action callback)
            {
                HotModifierKeys modifiers = 0;
                Keys            windowKey = key;

                if ((windowKey & Keys.Shift) > 0)
                {
                    windowKey -= Keys.Shift; modifiers |= HotModifierKeys.Shift;
                }
                if ((windowKey & Keys.Control) > 0)
                {
                    windowKey -= Keys.Control; modifiers |= HotModifierKeys.Control;
                }
                if ((windowKey & Keys.Alt) > 0)
                {
                    windowKey -= Keys.Alt; modifiers |= HotModifierKeys.Alt;
                }
                if (Windows.RegisterHotKey(Handle, NextID, (uint)modifiers, (uint)windowKey))
                {
                    HotKeyKeys.Add(key);
                    HotKeysCallbacks.Add(callback);
                    HotKeyIDs.Add(NextID++);
                }
            }
Ejemplo n.º 12
0
        private static string GetModifierString(HotModifierKeys keys, params HotModifierKeys[] modifiers)
        {
            StringBuilder returnValue = new StringBuilder();
            foreach (HotModifierKeys mod in modifiers)
                if ((keys & mod) > 0)
                    returnValue.AppendFormat("{0}+", (mod == HotModifierKeys.Control) ? "Ctrl" : mod.ToString());

            return returnValue.ToString();
        }