C# Console ReadKey() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Console

Definition

In C#, Console.ReadKey waits for a single key and returns a ConsoleKeyInfo value with the key, character (if any), and modifier keys.

Pass intercept: true (or true) so the key is not echoed on the screen—useful for “Press any key…” pauses and simple menus. Unlike ReadLine, you do not need to press Enter for letter keys.

This is a static member of System.Console. You call it with the type name, such as Console.ReadKey(...). Console is the everyday API for reading from standard input and writing to standard output in C# console apps.

Syntax

Call ReadKey or ReadKey(true) and inspect Key or KeyChar.

C#
ConsoleKeyInfo info = Console.ReadKey();
ConsoleKeyInfo hidden = Console.ReadKey(true);
CallWhat it does
Console.ReadKey()Reads a key and echoes it.
Console.ReadKey(true)Reads a key without echoing (intercept).

Some keys (arrows, function keys) have KeyChar of \\0. Check ConsoleKey for those.

Library declarations
C#
public static ConsoleKeyInfo ReadKey();
public static ConsoleKeyInfo ReadKey(bool intercept);

Parameters

ParameterDescription
interceptOptional. When true, the key is not displayed on the console.

Return Value

Return ValueDescription
ConsoleKeyInfoDescribes the key (Key), character (KeyChar), and modifiers.

C# Examples

Example 1 — Press Any Key to Continue

Show a pause message and wait with intercept so the key is not echoed.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("Working...");
        Console.WriteLine("Press any key to continue...");
        Console.ReadKey(true);
        Console.WriteLine("Thanks!");
    }
}

How It Works

  1. Intercept true. The pressed key does not appear between the messages.
  2. Sample pause. Output jumps to Thanks after a key (key itself not shown).
  3. Blocking wait. Main stops until a key arrives.
  4. Simple UX. Common pattern at the end of small demos.

Example 2 — Choose 1 or 2 With ReadKey

Build a tiny menu that reacts to a digit key.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("1) Greet");
        Console.WriteLine("2) Exit");
        Console.Write("Choice: ");
        ConsoleKeyInfo info = Console.ReadKey(true);
        Console.WriteLine(info.KeyChar);
        if (info.KeyChar == '1') {
            Console.WriteLine("Hello!");
        } else {
            Console.WriteLine("Goodbye");
        }
    }
}

How It Works

  1. Hidden then print. Intercept hides the key; we print KeyChar ourselves.
  2. Sample choice. sample output shows selecting 1.
  3. No Enter needed. The digit key alone is enough.
  4. Branch. Compare KeyChar (or Key) to decide the path.

Example 3 — Show ConsoleKey for Arrow Keys

Print the Key enum when KeyChar is not useful.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("Press an arrow key...");
        ConsoleKeyInfo info = Console.ReadKey(true);
        Console.WriteLine("Key = " + info.Key);
        Console.WriteLine("KeyChar empty? " + (info.KeyChar == '\0'));
    }
}

How It Works

  1. Special keys. Arrows often have no printable KeyChar.
  2. Use Key. The ConsoleKey enum names the physical key.
  3. Sample RightArrow. Output assumes the right arrow was pressed.
  4. Intercept again. Avoids odd echo for non-character keys.

Frequently Asked Questions

When true, the key is read but not shown on the screen.
Usually no for letter and digit keys. ReadKey returns after one key press.
A small struct with Key, KeyChar, and modifier information.
ReadKey is one key. ReadLine is a whole line ending with Enter.
Console key APIs expect an interactive console; redirected or unsupported hosts may throw or behave differently.

Next: ReadLine()

Read a full line of text from the console, or null at end of file with System.Console.

ReadLine() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful