控制台获得键盘事件

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();
}
posted on 2014-04-15 18:54  知鸟  阅读(681)  评论(0编辑  收藏  举报