I'm Going to start a console application. The problem is how to determine that the CTRL key is pressed alone without any other key.
using System;
using System.Text;
public class ConsoleKeyExample
{
public static void Main()
{
ConsoleKeyInfo input;
do
{
input = Console.ReadKey(true);
StringBuilder output = new StringBuilder(String.Format("You pressed {0}",input.Key.ToString()));
Console.WriteLine(output.ToString());
if ((input.Modifiers & ConsoleModifiers.Control) != 0)
{
Console.WriteLine("CTRL Pressed");
}
} while (input.Key != ConsoleKey.Escape);
}
}
I want to monitor the behavior of the CTRL key. After tracing this code, I put a checkpoint on readkey line, but when I press CTRL, nothing happens, but when I press any other key like "K" it starts reading key from the keyboard.