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 fo
Just add the following where you want to wait:
while (!Console.KeyAvailable) {}
You can poll on Console.KeyAvailable to know if you can read anything.
You want to look into using Event Handlers. For using Windows forms the following should be helpful. Control.Keypress Event (System.Windows.Forms). For a good overview of Event Handlers in general, take a look at EventHandling in .NET using C#.
For a console application, you should look into the Console.CancelKeyPress Event
function.