Saturday, August 10, 2013

Check The Type of Key Press on the Keyboard using C#.Net

                In previous article Console Class is published.Now i will publish an article about check the type of key press on the keyboard using c#.Net.

                  This Can be possible by using "KeyInfo" property.

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

namespace Consolecls
    class Class5
        static void Main(string[] args)
            //Key Avialble Key(You Must Use "System.Threading" namespace)
            ConsoleKeyInfo cki = new ConsoleKeyInfo();

                Console.WriteLine("\nPress a key to display; press the 'x' key to quit.");

                // Your code could perform some useful task in the following loop. However, 
                // for the sake of this example we'll merely pause for a quarter second.

                while (Console.KeyAvailable == false)
                    Thread.Sleep(250); // Loop until input is entered.
                cki = Console.ReadKey(true);
                Console.WriteLine("You pressed the '{0}' key.", cki.Key);
            } while (cki.Key != ConsoleKey.X);
Console Class 2

No comments: