Ian H.
Ian H.

Reputation: 3919

C# Console - Run Event on Key Press

I just wanted to ask if it was possible to make an event run if the player presses a specific button. This should be tested at every point in the console application but not if there is a Console.ReadLine() event used at the moment.

Is there a way to do this?

Upvotes: 0

Views: 178

Answers (1)

Suren Srapyan
Suren Srapyan

Reputation: 68645

You can use Console.ReadKey() method like this

ConsoleKeyInfo keyInfo = Console.ReadKey();

if(keyInfo.Key == ConsoleKey.A)
{

}

For more info see https://msdn.microsoft.com/en-us/library/system.console.readkey(v=vs.110).aspx

Upvotes: 1

Related Questions