Subject: Using keyboard events.
Posted By: edurazee Post Date: 7/23/2008 12:24:59 AM
 
quote:
How can I replace the while looping statement with keyboard events and event handlers.

using System;

class Program
{
    static void Main(string [] args)
    {
        ConsoleKey consoleKey;
            
        while(true)
        {
            consoleKey = Console.ReadKey(true).Key;

            if ( consoleKey == ConsoleKey.Enter )
            {
                Console.WriteLine("Hello World!");
            }
            else if ( consoleKey == ConsoleKey.F10)
            {
                break;
            }
        }
    }
}


Reply By: David_0223 Reply Date: 7/23/2008 8:12:03 AM
You must have a loop that checks for events on the computer.  In a console application, such as you have here, you must provide the loop.  If you re-write this as a Windows application, Windows will provide the loop.  Get a book on begining Windows programming for C#.

What you don't know can hurt you!
Reply By: edurazee Reply Date: 7/24/2008 4:49:45 AM
Thanks for clearing my concept.

I always welcome a person who adds something to my knowledge.

It is never a shame if I don't know something, but it is a sin if I don't want to know something.


Go to topic 72463

Return to index page 2
Return to index page 1