I have a console app that prompts the user for multiple inputs. I’d like the user to be able to press escape after any prompt to cancel the operation.
Something like:
if (Console.ReadKey().Key != ConsoleKey.Escape) {
string input = Console.ReadLine();
...
}
The problem with this, however, is that if a key other than escape is pressed it won’t be part of the input (returned from ReadLine).
Is there a way to “peek” at the next key, or otherwise do this?
Usage example: