我想:ESC鍵
while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
{
// do something
}
這不能幫助我並沒有做什麼,我需要.. 我的代碼是:
Console.WriteLine("Please enter your Login Details:");
Console.Write("User Name: ");
string userName = Console.ReadLine();
Console.Write("Password: ");
string Password = Console.ReadLine();
if (cmd.Login(userName, Password))
{
// my rest of my code
}
我需要在任何console.readline()
如果我按下ESC去第一個代碼或開始把用戶名和密碼... 我需要按ESC在我的應用程序它重新啓動到第一階段在任何時間和任何階段..這可能嗎?
的[偵聽在.NET控制檯應用程序按鍵]可能的複製(http://stackoverflow.com/questions/5891538/listen-for-key-press-in-net-console-app) – KidCode
[檢查這個問題!](http://stackoverflow.com/questions/5891538/listen-for-key-press-in-net-console-app) – KidCode
閱讀整個問題!他不問如何暫停,直到按下一個鍵。他問他如何在「Read」或「ReadLine」中捕獲按鍵,這樣如果用戶按下ESC,「Read」將中止,並且可以跳回到登錄過程的開始。 –