Beispiel #1
0
 /// <summary>
 /// Removes a registered callbacks by the token.
 /// </summary>
 /// <param name="token">The token of the registered callback.</param>
 /// <remarks>If the token is not known anymore nothing happen.</remarks>
 public void RemoveCallback(KeyboardWatchToken token)
 {
     if (_callbacks.ContainsKey(token))
     {
         _callbacks.Remove(token);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Registers a callback which got called if one of the given keys changed their state to one of the given states.
        /// </summary>
        /// <param name="keys">The keys which has to be watched for.</param>
        /// <param name="states">The key states which has to be watched for.</param>
        /// <param name="callback">The callback to be called.</param>
        /// <returns>A token which represends the current callback to be used for <see cref="DW.WPFToolkit.Helpers.KeyboardWatcher.RemoveCallback" />.</returns>
        public KeyboardWatchToken AddCallback(IEnumerable <Key> keys, IEnumerable <KeyState> states, Action <KeyStateChangedArgs> callback)
        {
            var token        = new KeyboardWatchToken();
            var callbackItem = new KeyboardWatcherCallback
            {
                Callback  = callback,
                Keys      = keys,
                KeyStates = states,
                Token     = token
            };

            _callbacks[token] = callbackItem;
            return(token);
        }