I'm writing a console app in C#, which reads user input using Console.ReadKey()
. It has code that's similar to this:
while(true)
{
switch(Console.ReadKey(true).Key)
{
case ConsoleKey.Enter:
//code
case ConsoleKey.UpArrow:
//code
case ConsoleKey.DownArrow:
//code
case ConsoleKey.Escape:
//code
}
}
Now the problem is, if the user holds down any key for more than half a second, Windows registers it as multiple key presses. So if, for the example, the Enter key is held down for a second, the code that goes after case ConsoleKey.Enter:
runs about ten times, and I don't want that.
How do I make it so that holding a button down registers as only one key press? Will I have to use Windows Forms for that? (currently my code only relies on the Console class).