控制台获得键盘事件

public static void Main(String[] args)
{
bool tag = true;
do
{
ConsoleKeyInfo info = Console.ReadKey();
switch (info.Key)
{
case ConsoleKey.E:
Console.WriteLine("exit");
tag = false;
break;
case ConsoleKey.UpArrow:
Console.WriteLine("Up");
break;
case ConsoleKey.DownArrow:
Console.WriteLine("Down");
break;
case ConsoleKey.LeftArrow:
Console.WriteLine("Left");
break;
case ConsoleKey.RightArrow:
Console.WriteLine("Right");
break;
default:
Console.WriteLine(info.Key);
break;
}
} while (tag);
Console.Read();
}
原文地址:https://www.cnblogs.com/izhiniao/p/3667057.html