Beispiel #1
0
        /// <inheritdoc />
        public override void UnregisterHotKey(VirtualKeys key, Modifiers modifiers)
        {
            // remove no repeat before adding to list to avoid getting different hash
            modifiers = (Modifiers)((uint)modifiers & 0xF);

            KeyModifierCombination combination = new KeyModifierCombination(key, modifiers);

            if (!HotKeys.ContainsKey(combination))
            {
                String error = $"Failed to unregister hotKey : HotKey \"{key}+{modifiers}\" is not registered";
                Logger.Warn(error);
                throw new HotKeyException(error);
            }

            try
            {
                HotKey tmpHotKey = HotKeys[combination];
                tmpHotKey.UnregisterHotKey();
                HotKeysId.Remove(tmpHotKey.Id);
                HotKeys.Remove(combination);
            }
            catch (HotKeyException e)
            {
                Logger.Warn("Failed to unregister hotKey : {0}", e.Message);
                throw;
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        public override void RemoveHotKeyAction(VirtualKeys key, Modifiers modifiers, EventHandler <HotKeyPressedEventArgs> handler)
        {
            // remove no repeat before adding to list to avoid getting different hash
            modifiers = (Modifiers)((uint)modifiers & 0xF);
            KeyModifierCombination combination = new KeyModifierCombination(key, modifiers);

            if (!HotKeys.ContainsKey(combination))
            {
                String error = $"No hotKey associated with {modifiers}+{key}";
                Logger.Warn(error);
                throw new HotKeyException(error);
            }

            HotKeys[combination].HotKeyPressedEvent -= handler;
        }
Beispiel #3
0
        /// <summary>
        /// Thread message event handler.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="handled">if set to <c>true</c> [handled].</param>
        private void ThreadMessageEventHandler(ref MSG msg, ref bool handled)
        {
            if (handled || msg.message != WM_HOTKEY)
            {
                return;
            }
            int         id         = (int)msg.wParam;
            VirtualKeys virtualKey = (VirtualKeys)(((int)msg.lParam >> 16) & 0xFFFF);
            Modifiers   modifiers  = (Modifiers)((int)msg.lParam & 0xFFFF);

            KeyModifierCombination keyModifierCombination = new KeyModifierCombination(virtualKey, modifiers);

            if (HotKeys.ContainsKey(keyModifierCombination))
            {
                HotKeyPressedEventArgs args = new HotKeyPressedEventArgs(msg.pt_x, msg.pt_y, msg.time, id, virtualKey, modifiers);
                HotKeys[keyModifierCombination].HotKeyPressed(args);
            }
        }