Use ConsoleKey to get input : ConsoleKey « Development « C# / CSharp Tutorial






using System;
using System.Collections.Generic;

class MainClass
{
    public static void Main()
    {
        ConsoleKeyInfo key;
        Console.WriteLine("Process input until the user enters Alt-X or Alt-x");
        
        do
        {
            key = Console.ReadKey(true);

            Console.WriteLine(key);
            if (key.Key == ConsoleKey.F1)
            {
               Console.WriteLine("F1");
            }

            // Handle backspace.
            if (key.Key == ConsoleKey.Backspace)
            {
                Console.WriteLine("Backspace");
            }
            // Handle Escape.
            else if (key.Key == ConsoleKey.Escape)
            {
                Console.WriteLine("Escape");
            }
            // Handle character input.
            else if (key.Key >= ConsoleKey.A && key.Key <= ConsoleKey.Z)
            {
                Console.WriteLine(">=ConsoleKey.A && <= ConsoleKey.Z");
            }
        } while (key.Key != ConsoleKey.X || key.Modifiers != ConsoleModifiers.Alt);

    }
}
Process input until the user enters Alt-X or Alt-x
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z
System.ConsoleKeyInfo
>=ConsoleKey.A && <= ConsoleKey.Z








14.9.ConsoleKey
14.9.1.Read keystrokes from the console by using ReadKey()
14.9.2.Use ConsoleKey to get input