I'm fairly new to C# and I'd appreciate your contribution.
At the moment, I have the following line on my code:
while (Console.ReadKey().Key != ConsoleKey.Q) { } //Exit on Q
So as you can see, on a Console Application, if the user presses Q the application exits. Fine. Now, the question is: is there any way to combine a ConsoleModifiers plus ConsoleKey? Instead of using the Q key, I'd prefer to use the Ctrl+Q on exit.
The reason why I want to achieve this is that I don't feel confortable to leave only one key on exit (makes easy to prevent that someone presses it accidently). Altough the syntax is completely incorrect, that's what I roughly would like to achieve:
ConsoleModifiers.Control + ConsoleKey.Q
Thanks in advance.
You can store ConsoleKeyInfo in variable and check for both parameters.
ConsoleKeyInfo c;
while ((c = Console.ReadKey()).Modifiers != ConsoleModifiers.Control
|| c.Key != ConsoleKey.Q) { } //Exit on Ctrl + Q
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With