Console.ReadKey Method (Boolean)
Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window.
Assembly: mscorlib (in mscorlib.dll)
[<HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)>] static member ReadKey : intercept:bool -> ConsoleKeyInfo
Determines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false.
Return ValueType: System.ConsoleKeyInfo
An object that describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The ConsoleKeyInfo object also describes, in a bitwise combination of ConsoleModifiers values, whether one or more Shift, Alt, or Ctrl modifier keys was pressed simultaneously with the console key.
The ReadKey method waits, that is, blocks on the thread issuing the ReadKey method, until a character or function key is pressed. A character or function key can be pressed in combination with one or more Alt, Ctrl, or Shift modifier keys. However, pressing a modifier key by itself will not cause the ReadKey method to return.
If the intercept parameter is true, the pressed key is intercepted and not displayed in the console window; otherwise, the pressed key is displayed.
One of the most common uses of the ReadKey method is to halt program execution until the user presses a key and the app either terminates or displays an additional window of information. The following example uses the method to wait for the user to press the Enter key before terminating the app. Note that, if the user presses any other key, it is not echoed to the console.
Available since 2.0