public bool Equals(KeyPress keyPress) { // If parameter is null, return false. if (Object.ReferenceEquals(keyPress, null)) { return(false); } // Optimization for a common success case. if (Object.ReferenceEquals(this, keyPress)) { return(true); } // If run-time types are not exactly what we expect, return false. if (this.GetType() != typeof(KeyEventInfo) && keyPress.GetType() != typeof(KeyPress)) { return(false); } // check for value equality on our member properties return(VkCode == (VirtualKey)keyPress.VkCode && ScanCode == (ScanCode)keyPress.ScanCode && (!keyPress.Extended && !Flags.HasFlag(KeyEventFlags.EXTENDED) || (keyPress.Extended && Flags.HasFlag(KeyEventFlags.EXTENDED)))); }