Console.KeyAvailable Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets a value indicating whether a key press is available in the input stream.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static member KeyAvailable : bool with get

Property Value

Type: System.Boolean

true if a key press is available; otherwise, false.

Exception Condition
IOException

An I/O error occurred.

InvalidOperationException

Standard input is redirected to a file instead of the keyboard.

The property value is returned immediately; that is, the KeyAvailable property does not block input until a key press is available.

Use the KeyAvailable property in conjunction with only the ReadKey method, not the Read or ReadLine methods.

The following example demonstrates how to use the KeyAvailable property to create a loop that runs until a key is pressed.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: