mscorlib(4.0.0.0) API with additions
ConsoleKeyInfo.cs
1 namespace System
2 {
5  public struct ConsoleKeyInfo
6  {
7  private char _keyChar;
8 
9  private ConsoleKey _key;
10 
11  private ConsoleModifiers _mods;
12 
15  public char KeyChar => _keyChar;
16 
19  public ConsoleKey Key => _key;
20 
23  public ConsoleModifiers Modifiers => _mods;
24 
35  public ConsoleKeyInfo(char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
36  {
37  if (key < (ConsoleKey)0 || key > (ConsoleKey)255)
38  {
39  throw new ArgumentOutOfRangeException("key", Environment.GetResourceString("ArgumentOutOfRange_ConsoleKey"));
40  }
41  _keyChar = keyChar;
42  _key = key;
43  _mods = (ConsoleModifiers)0;
44  if (shift)
45  {
46  _mods |= ConsoleModifiers.Shift;
47  }
48  if (alt)
49  {
50  _mods |= ConsoleModifiers.Alt;
51  }
52  if (control)
53  {
54  _mods |= ConsoleModifiers.Control;
55  }
56  }
57 
62  public override bool Equals(object value)
63  {
64  if (value is ConsoleKeyInfo)
65  {
66  return Equals((ConsoleKeyInfo)value);
67  }
68  return false;
69  }
70 
75  public bool Equals(ConsoleKeyInfo obj)
76  {
77  if (obj._keyChar == _keyChar && obj._key == _key)
78  {
79  return obj._mods == _mods;
80  }
81  return false;
82  }
83 
89  public static bool operator ==(ConsoleKeyInfo a, ConsoleKeyInfo b)
90  {
91  return a.Equals(b);
92  }
93 
99  public static bool operator !=(ConsoleKeyInfo a, ConsoleKeyInfo b)
100  {
101  return !(a == b);
102  }
103 
106  public override int GetHashCode()
107  {
108  return (int)_keyChar | (int)_mods;
109  }
110  }
111 }
ConsoleModifiers Modifiers
Gets a bitwise combination of T:System.ConsoleModifiers values that specifies one or more modifier ke...
Definition: __Canon.cs:3
override bool Equals(object value)
Gets a value indicating whether the specified object is equal to the current T:System....
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static bool operator==(ConsoleKeyInfo a, ConsoleKeyInfo b)
Indicates whether the specified T:System.ConsoleKeyInfo objects are equal.
static bool operator !=(ConsoleKeyInfo a, ConsoleKeyInfo b)
Indicates whether the specified T:System.ConsoleKeyInfo objects are not equal.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
char KeyChar
Gets the Unicode character represented by the current T:System.ConsoleKeyInfo object.
ConsoleKey Key
Gets the console key represented by the current T:System.ConsoleKeyInfo object.
Describes the console key that was pressed, including the character represented by the console key an...
ConsoleModifiers
Represents the SHIFT, ALT, and CTRL modifier keys on a keyboard.
bool Equals(ConsoleKeyInfo obj)
Gets a value indicating whether the specified T:System.ConsoleKeyInfo object is equal to the current ...
override int GetHashCode()
Returns the hash code for the current T:System.ConsoleKeyInfo object.
Specifies that the class can be serialized.
ConsoleKeyInfo(char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
Initializes a new instance of the T:System.ConsoleKeyInfo structure using the specified character,...
ConsoleKey
Specifies the standard keys on a console.
Definition: ConsoleKey.cs:5