Disabling input in C# Console until certain task is completed

后端 未结 2 1155
独厮守ぢ
独厮守ぢ 2020-12-02 02:35

I\'m working on a little part of my program, handling the input, basically I have this little code:

bool Done = false;
while (!Done)
{
  ConsoleKeyInfo key =         


        
相关标签:
2条回答
  • 2020-12-02 02:52

    You can not block input, Even if you do not process it, it goes to the keyboard buffer.

    You can simply stop getting them out of the buffer though.

    0 讨论(0)
  • 2020-12-02 03:14

    Not so sure this make sense, personally I like it when keystrokes don't disappear and I can type ahead. But you can flush the keyboard buffer like this:

    while (!Done)
    {
        while (Console.KeyAvailable) Console.ReadKey(true);
        ConsoleKeyInfo key = Console.ReadKey(true);
        // etc..
    }
    
    0 讨论(0)
提交回复
热议问题