C# – 2 – Simple keyboard reader

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class KeyBoardInputAndOutput
{
public static void Main()
{
Console.TreatControlCAsInput = true;
ConsoleKeyInfo key;

Console.WriteLine(“Press the buttons on the keyboard to see the output”);

do
{
key = Console.ReadKey();
Console.WriteLine(” : is your input.”);
if ((key.Modifiers & ConsoleModifiers.Alt) != 0)
{
Console.Write(“ALT+”);
}
else if ((key.Modifiers & ConsoleModifiers.Shift) != 0)
{
Console.Write(“SHIFT+”);
}
else if ((key.Modifiers & ConsoleModifiers.Control) != 0)
{
Console.Write(“CTL+”);
}

Console.WriteLine(key.Key.ToString() + ” : is system print.”);

} while (key.Key != ConsoleKey.Escape);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s