Exemplo n.º 1
0
        /// <summary>
        /// Compares two KeyboardStates and returns the compared keys.
        /// </summary>
        /// <returns>
        /// Item1: Keys that are in this state and not the other.
        /// Item2: Keys that are in state, but not in this one. 
        /// </returns>
        public Tuple<Keys[], Keys[]> Compare(KeyboardState state)
        {
            if (state.Keys == null)
                return new Tuple<Keys[], Keys[]>(new Keys[] { }, new Keys[] { });

            // Would it be faster to assume the size of the array? then resize it.
            var odds1 = new List<Keys>();
            var odds2 = new List<Keys>();

            foreach (var key in Keys)
            {
                if (Array.IndexOf(state.Keys, key) == -1)
                    odds1.Add(key);
            }

            foreach (var key in state.Keys)
            {
                if (Array.IndexOf(Keys, key) == -1)
                    odds2.Add(key);
            }

            return new Tuple<Keys[], Keys[]>(odds1.ToArray(), odds2.ToArray());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of <see cref="KeyEventArgs"/>.
 /// </summary>
 public KeyEventArgs(KeyboardState state, Keys key, char keyChar)
 {
     this.Key = key;
     this.State = state;
     this.KeyChar = keyChar;
 }