KalEl KalEl - 1 month ago 11
C# Question

C#: Check if any key was pressed in Console

Both

Console.Read()
and
Console.ReadKey()
seem to wait for a key to be pressed. How can I detect if anything was pressed without actually asking for the program to wait till a key is pressed?

Answer

You can poll on Console.KeyAvailable to know if you can read anything.