Translate

Mittwoch, 4. November 2015

Read special keys from Console in C#

do
                    {
                        result = Console.ReadKey();
                        if (result.KeyChar == 'r' || result.KeyChar == 'R' || result.KeyChar == 'h' || result.KeyChar == 'H')
                        {
                            isKeyValid = true;
                        }
                    }
                    while (!isKeyValid);

                    switch(result.KeyChar)
                    {
                        case 'r': Restart(client); break;
                        case 'R': Restart(client); break;
                        case 'h': Shutdown(client); break;
                        case 'H': Shutdown(client); break;
                    }

                    Console.WriteLine("Beliebige Taste drücken um das Programm zu beenden\n");
                    result = Console.ReadKey();

Keine Kommentare:

Kommentar veröffentlichen