Ask coding questions

← Back to all posts
How to detect user keypress
h
JacobMcPherson1 (191)

How do you detect if the user presses a key in C#

Answered by Coder100 (16915) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (16915)

ez

using System;

class Bruh {
  public static void Main(string[] args) {
    Console.Write("Press Key: ");
    char key = Console.ReadKey().KeyChar;
    Console.WriteLine($"You Pressed {key}");
  }
}