Last Updated : 11 Jul, 2025
Console.KeyAvailable Property is used to get a value which shows whether a key press is available in the input stream. This property does not block input until a key press is available.
Syntax: public static bool KeyAvailable { get; }
Property Value: It will return true if a key press is available otherwise, it returns false.
Exceptions:
Example:
C#
// C# Program to demonstrate
// KeyAvailable property
using System;
using System.Threading;
namespace GFG {
class GFG {
public static void Main()
{
// declare a new ConsoleKeyInfo object
ConsoleKeyInfo c = new ConsoleKeyInfo();
// outer loop to work until 'z' is pressed
do {
Console.WriteLine("\nPress a key to display; "+
"press the 'z' key to quit.");
// inner loop to check whether a key
// is pressed using KeyAvailable
while (Console.KeyAvailable == false)
// Loop until input is entered.
Thread.Sleep(50);
c = Console.ReadKey(true);
Console.WriteLine("You pressed the '{0}' key.", c.Key);
} while (c.Key != ConsoleKey.Z);
}
}
}
Output:
Reference:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4