阅读转义键 [英] reading the escape key
本文介绍了阅读转义键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
f(){
info=console.readkey();
if(info == ConsoleKey.Escape)
console.write("exit");
int n = Convert.ToInt32(Console.ReadLine());
}
我需要说的是,如果按下转义",请退出.但是
如果用户的第一个按下的字符没有逃脱,则不会在窗口中显示...
i need to say that if "escape" is pressed,quit.but
the first pressed character by user is not displayed in the window if its not escape...
推荐答案
if(Console.ReadKey() == ConsoleKey.Escape)
您可以在下面尝试,
You might try below,
static void ReadUserData()
{
var info = Console.ReadKey();
if (info.Key == ConsoleKey.Escape)
{
Console.WriteLine("exit");
}
else
{
Console.WriteLine(string.Format("\nKey has been pressed : {0}", info.Key));
int n;
n = Int32.TryParse(Console.ReadLine(), out n) ? n : 0;
Console.WriteLine(n);
}
}
:)
:)
这篇关于阅读转义键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文