Console.KeyAvailable Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on 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

An I/O error occurred.


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