Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
KeyEvent.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.Paradox.Input
6 {
7  /// <summary>
8  /// A keyboard event.
9  /// </summary>
10  public struct KeyEvent : IEquatable<KeyEvent>
11  {
12  /// <summary>
13  /// The key that is being pressed or released.
14  /// </summary>
15  public readonly Keys Key;
16 
17  /// <summary>
18  /// The key event type (released or pressed).
19  /// </summary>
20  public readonly KeyEventType Type;
21 
22  /// <summary>
23  /// Initializes a new instance of the <see cref="KeyEvent"/> struct.
24  /// </summary>
25  /// <param name="key">The key.</param>
26  /// <param name="type">The type.</param>
27  public KeyEvent(Keys key, KeyEventType type)
28  {
29  Key = key;
30  Type = type;
31  }
32 
33  /// <inheritdoc/>
34  public bool Equals(KeyEvent other)
35  {
36  return Key == other.Key && Type == other.Type;
37  }
38 
39  /// <inheritdoc/>
40  public override bool Equals(object obj)
41  {
42  if (ReferenceEquals(null, obj)) return false;
43  return obj is KeyEvent && Equals((KeyEvent)obj);
44  }
45 
46  /// <inheritdoc/>
47  public override int GetHashCode()
48  {
49  unchecked
50  {
51  return ((int)Key * 397) ^ (int)Type;
52  }
53  }
54 
55  /// <summary>
56  /// Implements the ==.
57  /// </summary>
58  /// <param name="left">The left.</param>
59  /// <param name="right">The right.</param>
60  /// <returns>The result of the operator.</returns>
61  public static bool operator ==(KeyEvent left, KeyEvent right)
62  {
63  return left.Equals(right);
64  }
65 
66  /// <summary>
67  /// Implements the !=.
68  /// </summary>
69  /// <param name="left">The left.</param>
70  /// <param name="right">The right.</param>
71  /// <returns>The result of the operator.</returns>
72  public static bool operator !=(KeyEvent left, KeyEvent right)
73  {
74  return !left.Equals(right);
75  }
76 
77  public override string ToString()
78  {
79  return string.Format("{0} ({1})", Key, Type == KeyEventType.Pressed ? "Pressed" : "Release");
80  }
81  }
82 }
Keys
Enumeration for keys.
Definition: Keys.cs:8
override bool Equals(object obj)
Definition: KeyEvent.cs:40
bool Equals(KeyEvent other)
Definition: KeyEvent.cs:34
readonly KeyEventType Type
The key event type (released or pressed).
Definition: KeyEvent.cs:20
readonly Keys Key
The key that is being pressed or released.
Definition: KeyEvent.cs:15
KeyEvent(Keys key, KeyEventType type)
Initializes a new instance of the KeyEvent struct.
Definition: KeyEvent.cs:27
KeyEventType
Used by KeyEvent
Definition: KeyEventType.cs:8