ConsoleKeyInfo keyInfo = Console.ReadKey();
ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Enter) { Console.WriteLine("You pressed the Enter key."); }
ConsoleKeyInfo keyInfo; do { keyInfo = Console.ReadKey(true); } while ((keyInfo.Modifiers & ConsoleModifiers.Alt) != 0 || (keyInfo.Modifiers & ConsoleModifiers.Control) != 0); Console.WriteLine("You pressed the {0} key.", keyInfo.Key);This code reads a key press from the console, but only accepts keys that were pressed without any modifier keys (such as alt or control). It continues to read keys until a valid one is pressed, then prints a message with the key that was pressed. The ConsoleKeyInfo class is part of the System.Console package library.