c#控制台应用程序怎么获取键盘上的上下左右键
1个回答
展开全部
直接上代码,如下
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();
}
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();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询