I'm developing a console application in which I need to detect several hotkeys such as Ctrl+N, Ctrl+O and Ctrl+S. Here's a part of the code that I use to recognize these hotkeys:
ConsoleKeyInfo input = Console.ReadKey(true);
if (input.Modifiers == ConsoleModifiers.Control)
{
if (input.Key == ConsoleKey.N)
{
// ...
}
else if (input.Key == ConsoleKey.O)
{
// ...
}
else if (input.Key == ConsoleKey.S)
{
//...
}
}
The code above works without any issues for Ctrl+N and Ctrl+O. But, I can't get it to work for Ctrl+S. After doing some quick testing, I found out that pressing Ctrl+S doesn't even do anything (meaning that the program is still waiting for the user to type something).
This issue only occurs with Ctrl+S. Using some simple if
statements for any other modifier (Shift for example) and key (N, O, etc) works fine.
Why does this happen? Is there a special meaning to the Ctrl+S combination? Is it possible to make this work? If yes, how?