I've got the following code trying to learn how to use the read.key method:
The problem is, is that once I run it, it just sits and itterates "your key is ". I don't press a key, it just keeps going and going. I figure, maybe I have a key pressed and don't realize it, but if I open a text editor and leave it alone no keys type out so there is something wrong with my code I would presume. Can anyone help me figure out why it's reading a key over and over and not waiting for me to actually press a key?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo keypress;
Console.WriteLine("Enter keystrokes. Enter Q to stop.");
do {
keypress = Console.ReadKey(); // read keystrokes
Console.WriteLine(" Your key is: " + keypress.KeyChar);
// Check for modifier keys.
if((ConsoleModifiers.Alt & keypress.Modifiers) != 0)
Console.WriteLine("Alt key pressed.");
if((ConsoleModifiers.Control & keypress.Modifiers) != 0)
Console.WriteLine("Control key pressed.");
if((ConsoleModifiers.Shift & keypress.Modifiers) != 0)
Console.WriteLine("Shift key pressed.");
} while(keypress.KeyChar != 'Q');
}
}
}
Comment