2014-04-06 32 views
-3

我想檢查用戶輸入是否爲元音。如果按下其他任何鍵,則應顯示錯誤。這是迄今爲止我所擁有的。我如何添加其他Keys? 電流輸出: 「鍵按下」 AC#檢查元音

static void Main(string[] args) 
    { 
     ConsoleKeyInfo A; 
     while (true) 
     { 
      A = Console.ReadKey(); 
      if (A.Key == ConsoleKey.A); 
      { 
       Console.WriteLine("A"); 
      } 
     } 
    } 

回答

0

你可以試試這個:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 
      { 
       if (keyData == Keys.F3) 
       { 
        //do something; 
       } 
       if(keyData ==Keys.Escape) 
       { 
        //do something; 
       } 
       if(keyData ==Keys.F2) 
       { 
        //do something; 
       } 
       return false; 
      } 
+0

這看起來像一個堅實的答案!雖然我得到的錯誤名稱'鑰匙'不存在於當前的情況下 – user3415389

+0

@ user3446201我認爲我超出範圍,你可以告訴在哪裏放置此代碼? – user3415389