コード例 #1
0
        /// <summary>
        /// Removes the specified hot key.
        /// </summary>
        /// <param name="state">The hot key to remove.</param>
        /// <returns>true if the hot key was removed successfully; otherwise false.</returns>
        /// <exception cref="ArgumentNullException">state is null</exception>
        /// <exception cref="ArgumentException">state was created by a different HotKeyComponent instance</exception>
        /// <exception cref="ArgumentException">state is invalid type</exception>
        public bool Remove(HotKeyState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            if (state.Owner != this)
            {
                throw new ArgumentException("The specified state was created by a different HotKeyComponent instance.", "state");
            }

            InternalHotKeyState hotkey = state as InternalHotKeyState; //cast state

            if (hotkey == null)                                        //validate state
            {
                throw new ArgumentException("The specified state is an invalid type.", "state");
            }

            if (localHotKeys.Remove(hotkey.ID)) //attempt to remove the hotkey
            {
                UnregisterHotKey(hotkey);       //unregister the hotkey
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Attempts to create a new system-wide hot key with repeat options, user state and a callback.
        /// </summary>
        /// <param name="hotkey">The hot key to register.</param>
        /// <param name="allow_repeat">true to allow repeating key events; otherwise, false.</param>
        /// <param name="state">An optional user state.</param>
        /// <param name="callback">A callback to invoke when the hot key is pressed.</param>
        /// <param name="result">When this method returns, contains an instance of a new state representing the hot key registration or null if the registration failed.</param>
        /// <returns>true if a new system-wide hot key was registered; otherwise, false.</returns>
        public bool TryAdd(HotKey hotkey, bool allow_repeat, object state, EventHandler <HotKeyActivatedEventArgs> callback, out HotKeyState result)
        {
            int id = ++HotKeyID;                //get next hotkey id

            if (id > MAXIMUM_REGISTERHOTKEY_ID) //max value id can be
            {
                throw new NotImplementedException($"HotKeyComponent cannot support identification numbers greater-than {MAXIMUM_REGISTERHOTKEY_ID}; previously unregistered hotkey ids should be reused.");
            }

            //create internal state for timestamps, state and callback
            InternalHotKeyState key_state = new InternalHotKeyState(this, id, hotkey, allow_repeat, state, callback);

            if (RegisterHotKey(key_state))       //register hot key with system
            {
                localHotKeys.Add(id, key_state); //add to collection
                result = key_state;              //set state
                return(true);
            }

            result = null;
            return(false);
        }
コード例 #3
0
 /// <summary>
 /// Attempts to create a new system-wide hot key with repeat options and a callback.
 /// </summary>
 /// <param name="key">The hot key to register.</param>
 /// <param name="modifier">The key modifier to associate with the key.</param>
 /// <param name="allow_repeat">true to allow repeating key events; otherwise, false.</param>
 /// <param name="callback">A callback to invoke when the hot key is pressed.</param>
 /// <param name="result">When this method returns, contains an instance of a new state representing the hot key registration or null if the registration failed.</param>
 /// <returns>true if a new system-wide hot key was registered; otherwise, false.</returns>
 public bool TryAdd(Keys key, Keys modifier, bool allow_repeat, EventHandler <HotKeyActivatedEventArgs> callback, out HotKeyState result)
 {
     return(TryAdd(key, modifier, allow_repeat, null, callback, out result));
 }
コード例 #4
0
 /// <summary>
 /// Attempts to create a new system-wide hot key with repeat options, user state and a callback.
 /// </summary>
 /// <param name="key">The hot key to register.</param>
 /// <param name="modifier">The key modifier to associate with the key.</param>
 /// <param name="allow_repeat">true to allow repeating key events; otherwise, false.</param>
 /// <param name="state">An optional user state.</param>
 /// <param name="callback">A callback to invoke when the hot key is pressed.</param>
 /// <param name="result">When this method returns, contains an instance of a new state representing the hot key registration or null if the registration failed.</param>
 /// <returns>true if a new system-wide hot key was registered; otherwise, false.</returns>
 public bool TryAdd(Keys key, Keys modifier, bool allow_repeat, object state, EventHandler <HotKeyActivatedEventArgs> callback, out HotKeyState result)
 {
     return(TryAdd(new HotKey(key, modifier), allow_repeat, state, callback, out result));
 }
コード例 #5
0
 /// <summary>
 /// Attempts to create a new system-wide hot key with repeat options and a user state.
 /// </summary>
 /// <param name="key">The hot key to register.</param>
 /// <param name="modifier">The key modifier to associate with the key.</param>
 /// <param name="allow_repeat">true to allow repeating key events; otherwise, false.</param>
 /// <param name="state">An optional user state.</param>
 /// <param name="result">When this method returns, contains an instance of a new state representing the hot key registration or null if the registration failed.</param>
 /// <returns>true if a new system-wide hot key was registered; otherwise, false.</returns>
 public bool TryAdd(Keys key, Keys modifier, bool allow_repeat, object state, out HotKeyState result)
 {
     return(TryAdd(key, modifier, allow_repeat, state, null, out result));
 }