I'm practicing with C# on my road to become a developer, so I'm kinda new with all this. I'm writing a simple console app to get some practice mileage, using the challenges I run into to learn more about how to work with the language. Because I love D&D I made a simple app that rolls different dice with pseudorandom numbers, with the possibility of adding modifiers. It asks the user which kind of die he/she would like to roll, how many, if there's any modifiers etc. etc.
In short, here's my problem: I want to give the user the possibility to exit the program at any given time by pressing ESC, while otherwise functioning as normal and handling user input as normal.
My console app is dependent on user input. All it does is ask the user for input, and then do something with that input, like a calculator. There's at least 6+ different moments where the user is prompted for input (type of die, amount of dice, adding modifiers etc.). What I want to do is offer the user the possibility of exiting the program at any time by pressing ESC instead of inputting their data. Because there are so many prompts, I want to prevent adding a check for ESC at every prompt so the code doesn't get repetitive and clunky.
I tried multithreading with a listener for the ESC key, but I found that it 'stole' the first character of every user input prompt. If I press ESC, the program neatly exits just like I want to, but if I don't want to exit and just input my data, the first keystroke is missing because it was used to check for the ESC key.
Is there a way to check if it's the ESC key, and if it isn't, just keep the input where it was?