Console ReadKey async or callback?

前端 未结 6 866
萌比男神i
萌比男神i 2021-01-04 14:04

I am trying to do a press Q to quit thing in the console window. I dont like my current implementation. Is there a way i can async or use a callback to get keys from the con

6条回答
  •  既然无缘
    2021-01-04 14:43

    You can use the KeyAvailable property (Framework 2.0) :

    if (System.Console.KeyAvailable)
    {
       ConsoleKeyInfo key = System.Console.ReadKey(true);//true don't print char on console
       if (key.Key == ConsoleKey.Q)
       {
           //Do something
       }
    }
    

提交回复
热议问题