internal void LogEvents(GlobalHotKey HotKey)
 {
     if (LogEvent)
     {
         txtLog.Text += string.Format("{0} : Hotkey Processed! Name: {1}; {2}",
                                      HotKey.Name, HotKey.FullInfo(), Environment.NewLine);
         txtLog.Select(txtLog.Text.Length, 0);
         txtLog.ScrollToCaret();
     }
 }
        GlobalHotKey CreateHotKey(string name, string shortcut, object tag)
        {
            object[] Parsed = HotKeyShared.ParseShortcut(shortcut);
            Modifiers mod = (Modifiers)Parsed.GetValue(0);
            Keys key = (Keys)Parsed.GetValue(1);

            GlobalHotKey toReturn = new GlobalHotKey(name, mod, key);
            toReturn.Tag = tag;

            return toReturn;
        }
Beispiel #3
0
 public static void RegisterHotkey(ModifierKeys modifiersKeys, string key)
 {
     Keys k = (Keys) new KeysConverter().ConvertFromString(key);
     if (_hk == null)
     {
         _hk = new GlobalHotKey("ShowHide", modifiersKeys, k, true);
         _hotKeyManager.AddGlobalHotKey(_hk);
         _hk.HotKeyPressed += (sender, args) => BubblesManager.ToggleShowHide();
     }
     else
     {
         _hk.Modifier = modifiersKeys;
         _hk.Key = k;
         _hk.Enabled = true;
     }
     if (OnHotkeyChanged != null)
         OnHotkeyChanged(_hk, new EventArgs());
 }
        private void RegisterGlobalHotKey(int id, GlobalHotKey hotKey)
        {
            if ((int)hwndSource.Handle != 0)
            {
                HelperMethods.RegisterHotKey(hwndSource.Handle, id, (int)hotKey.Modifier, (int)(hotKey.Key));
                int error = Marshal.GetLastWin32Error();
                if (error != 0)
                {
                    if (!this.SuppressException)
                    {
                        Exception e = new Win32Exception(error);

                        if (error == 1409)
                            throw new HotKeyAlreadyRegisteredException(e.Message, hotKey, e);
                        else if (error != 2)
                            throw e;
                    }
                }
            }
            else
                if (!this.SuppressException)
                {
                    throw new InvalidOperationException("Handle is invalid");
                }
        }
        /// <summary>Unregisters a GlobalHotKey.
        /// </summary>
        /// <param name="hotKey">The hotKey to be removed</param>
        /// <returns>True if success, otherwise false</returns>
        public bool RemoveGlobalHotKey(GlobalHotKey hotKey)
        {
            if (GlobalHotKeyContainer.Remove(hotKey) == true)
            {
                --GlobalHotKeyCount;

                if (hotKey.Enabled)
                    UnregisterGlobalHotKey(hotKey.Id);

                hotKey.PropertyChanged -= GlobalHotKeyPropertyChanged;
                return true;
            }
            else { return false; }
        }
        /// <summary>Registers a GlobalHotKey if enabled.
        /// </summary>
        /// <param name="hotKey">The hotKey which will be added. Must not be null and can be registered only once.</param>
        /// <exception cref="HotKeyAlreadyRegisteredException">Thrown is a GlobalHotkey with the same name, and or key and modifier has already been added.</exception>
        /// <exception cref="System.ArgumentNullException">thrown if a the HotKey to be added is null, or the key is not specified.</exception>
        public bool AddGlobalHotKey(GlobalHotKey hotKey)
        {
            if (hotKey == null)
            {
                if (!this.SuppressException)
                    throw new ArgumentNullException("value");

                return false;
            }
            if (hotKey.Key == 0)
            {
                if (!this.SuppressException)
                    throw new ArgumentNullException("value.Key");

                return false;
            }
            if (GlobalHotKeyContainer.Contains(hotKey))
            {
                if (!this.SuppressException)
                    throw new HotKeyAlreadyRegisteredException("HotKey already registered!", hotKey);

                return false;
            }

            int id = idGen.Next();
            if (hotKey.Enabled)
                RegisterGlobalHotKey(id, hotKey);
            hotKey.Id = id;
            hotKey.PropertyChanged += GlobalHotKeyPropertyChanged;
            GlobalHotKeyContainer.Add(hotKey);
            ++GlobalHotKeyCount;
            return true;
        }
 public HotKeyAlreadyRegisteredException(string message, GlobalHotKey hotKey, Exception inner)
     : base(message, inner)
 {
     HotKey = hotKey;
 }
 public HotKeyUnregistrationFailedException(string message, GlobalHotKey hotKey, Exception inner)
     : base(message, inner)
 {
     HotKey = hotKey;
 }
 public HotKeyRegistrationFailedException(string message, GlobalHotKey hotKey)
     : base(message)
 {
     HotKey = hotKey;
 }
 public GlobalHotKeyEventArgs(GlobalHotKey hotKey)
 {
     HotKey = hotKey;
 }
Beispiel #11
0
 public static void Dispose()
 {
     _hotKeyManager.Dispose();
     _hotKeyManager = null;
     _hk = null;
 }
        private void RegisterGlobalHotKey(int id, GlobalHotKey hotKey)
        {
            if ((int)FormHandle != 0)
            {
                if (hotKey.Key == Keys.LWin && (hotKey.Modifier & Modifiers.Win) == Modifiers.None)
                    Win32.RegisterHotKey(FormHandle, id, (int)(hotKey.Modifier | Modifiers.Win), (int)hotKey.Key);
                else
                    Win32.RegisterHotKey(FormHandle, id, (int)hotKey.Modifier, (int)(hotKey.Key));

                int error = Marshal.GetLastWin32Error();
                if (error != 0)
                {
                    if (!this.SuppressException)
                    {
                        Exception e = new Win32Exception(error);

                        if (error == 1409)
                            throw new HotKeyAlreadyRegisteredException(e.Message, hotKey, e);
                        else if (error != 2)
                            throw e; //ToDo: Fix here: File not found exception
                    }
                }
            }
            else
                if (!this.SuppressException)
                {
                    throw new InvalidOperationException("Handle is invalid");
                }
        }
Beispiel #13
0
 private void GlobalHotKeyPressed(GlobalHotKey obj)
 {
     BringToFront(BRING_TO_FRONT_OPTS.AlwaysKeyboardFocus);
 }
Beispiel #14
0
 private void onHotKeyPressed(GlobalHotKey _) => selectWindowFromScreen();