using System;
namespace Cosmos.System
{
///
/// KeyEvent class. Represent key event.
///
public class KeyEvent
{
///
/// Key event type.
///
public enum KeyEventType
{
Make,
Break
}
// todo: once Github issue #137 is fixed, replace this class with ConsoleKeyInfo struct.
// Well, this one has more features
///
/// Get and set key char.
///
public char KeyChar
{
get;
set;
}
///
/// Get and set key.
///
public ConsoleKeyEx Key
{
get;
set;
}
///
/// Get and set console modifiers.
///
public ConsoleModifiers Modifiers
{
get;
set;
}
///
/// Get and set key event type.
///
public KeyEventType Type { get; set; }
///
/// Create new instance of the class.
///
public KeyEvent()
{
KeyChar = '\0';
Key = ConsoleKeyEx.NoName;
this.Modifiers = (ConsoleModifiers)0;
Type = KeyEventType.Make;
}
///
/// Create new instance of the class.
///
/// Key char.
/// Key.
/// Shift.
/// Alt.
/// Ctrl.
/// Type.
public KeyEvent(char keyChar, ConsoleKeyEx key, bool shift, bool alt, bool control, KeyEventType type)
{
this.KeyChar = keyChar;
this.Key = key;
this.Modifiers = (ConsoleModifiers)0;
if (shift)
{
this.Modifiers |= ConsoleModifiers.Shift;
}
if (alt)
{
this.Modifiers |= ConsoleModifiers.Alt;
}
if (control)
{
this.Modifiers |= ConsoleModifiers.Control;
}
this.Type = type;
}
}
}