Console.ReadKey - bereitet probleme

  • VB.NET

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von Mr. VB.

    Console.ReadKey - bereitet probleme

    Hi,

    ich bin dabei, an meiner Consolen-App etwas zumzubasteln, und möchte, dass mit dem Stastendruck Y/N was gemacht wird, also mit Console.ReadKey...

    Leider stell ich fest, das sich das nicht so einfach wie Console.ReadLine behandeln läst.
    Habe es so probiert: If Console.ReadKey.Trim.ToLower = "y" then ...

    Jedoch kommt eine Fehlermeldung, dass Strung nicht in Bolean konvertiert werden kann...


    Sry für meine Frage, wenn sie etwas doof ist, aber weis das nun mal net, und möchte gerne wissen, wie ich das
    sonst machen kann?

    mfg

    gfcwfzkm
    Beispiel in C#

    VB.NET-Quellcode

    1. using System;
    2. class Example
    3. {
    4. public static void Main()
    5. {
    6. ConsoleKeyInfo cki;
    7. // Prevent example from ending if CTL+C is pressed.
    8. Console.TreatControlCAsInput = true;
    9. Console.WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console key.");
    10. Console.WriteLine("Press the Escape (Esc) key to quit: \n");
    11. do
    12. {
    13. cki = Console.ReadKey();
    14. Console.Write(" --- You pressed ");
    15. if((cki.Modifiers & ConsoleModifiers.Alt) != 0) Console.Write("ALT+");
    16. if((cki.Modifiers & ConsoleModifiers.Shift) != 0) Console.Write("SHIFT+");
    17. if((cki.Modifiers & ConsoleModifiers.Control) != 0) Console.Write("CTL+");
    18. Console.WriteLine(cki.Key.ToString());
    19. } while (cki.Key != ConsoleKey.Escape);
    20. }
    21. }
    22. // This example displays output similar to the following:
    23. // Press any combination of CTL, ALT, and SHIFT, and a console key.
    24. // Press the Escape (Esc) key to quit:
    25. //
    26. // a --- You pressed A
    27. // k --- You pressed ALT+K
    28. //--- You pressed CTL+P
    29. // --- You pressed RightArrow
    30. // R --- You pressed SHIFT+R
    31. // --- You pressed CTL+I
    32. // j --- You pressed ALT+J
    33. // O --- You pressed SHIFT+O
    34. // § --- You pressed CTL+U