예제 #1
0
        public bool IsAlreadyRegistered(Hotkey hotkey)
        {
            if (User32.RegisterHotKey(m_dummyWindow.Handle, hotkey.GetHashCode(), (int)hotkey.Modifiers, (int)hotkey.Key))
            {
                bool success = User32.UnregisterHotKey(m_dummyWindow.Handle, hotkey.GetHashCode());
                Debug.Assert(success);
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Registers the hotkey.
        /// </summary>
        /// <param name="hotkey">The hotkey.</param>
        /// <param name="handler">The handler.</param>
        /// <exception cref="ArgumentException">If the given hotkey is already registered in our application.</exception>
        /// <returns></returns>
        public bool RegisterHotkey(Hotkey hotkey, EventHandler handler)
        {
            if (hotkey == Hotkey.None)
            {
                return(true);
            }

            if (m_hotkeyHandlers.Keys.Contains(hotkey))
            {
                throw new ArgumentException("Hotkey " + hotkey + " is already registered");
            }

            if (handler == null)
            {
                throw new ArgumentException("", "handler");
            }

            if (User32.RegisterHotKey(m_dummyWindow.Handle, hotkey.GetHashCode(), (int)hotkey.Modifiers, (int)hotkey.Key))
            {
                m_hotkeyHandlers[hotkey] = handler;
                return(true);
            }

            return(false);
        }
예제 #3
0
 /// <summary>
 /// Unregisters the hotkey.
 /// </summary>
 /// <param name="hotkey">The hotkey.</param>
 /// <returns></returns>
 public bool UnregisterHotkey(Hotkey hotkey)
 {
     m_hotkeyHandlers.Remove(hotkey);
     return(User32.UnregisterHotKey(m_dummyWindow.Handle, hotkey.GetHashCode()));
 }