diff --git a/Source/OpenTK/Input/KeyboardState.cs b/Source/OpenTK/Input/KeyboardState.cs index 612dc963..99dea373 100644 --- a/Source/OpenTK/Input/KeyboardState.cs +++ b/Source/OpenTK/Input/KeyboardState.cs @@ -84,6 +84,81 @@ namespace OpenTK.Input return !ReadBit((int)key); } + /// + /// Checks whether two instances are equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is equal to right; false otherwise. + /// + public static bool operator ==(KeyboardState left, KeyboardState right) + { + return left.Equals(right); + } + + /// + /// Checks whether two instances are not equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is not equal to right; false otherwise. + /// + public static bool operator !=(KeyboardState left, KeyboardState right) + { + return !left.Equals(right); + } + + /// + /// Compares to an object instance for equality. + /// + /// + /// The to compare to. + /// + /// + /// True if this instance is equal to obj; false otherwise. + /// + public override bool Equals(object obj) + { + if (obj is KeyboardState) + { + return this == (KeyboardState)obj; + } + else + { + return false; + } + } + + /// + /// Generates a hashcode for the current instance. + /// + /// + /// A represting the hashcode for this instance. + /// + public override int GetHashCode() + { + unsafe + { + fixed (int* k = Keys) + { + int hashcode = 0; + for (int i = 0; i < NumInts; i++) + hashcode ^= (k + i)->GetHashCode(); + return hashcode; + } + } + } + #endregion #region Internal Members