how to bind a specific key to a specific action by using Console.ReadKey() method

Viewed 23

how to make the action happen when a certain key is pressed? can this be done with Console.ReadKey();

The code does not work! this is just a schematic image so you can understand what I mean

static void Play()
{
    if (Console.ReadKey() == 'q')
    {
        Console.Beep(523, 500);
    }
2 Answers

This will work, but the ReadKey method is in a loop normally when key is pressed then if or case statements are used to determine pressed key. If you want to app to listen for key presses and assign delegates based on user keypresses, its a bit more tricky. enter link description here

Another thing you can do is to create an async task or thread that goes into a loop and reads the keyboard input blocking the input and based on the results does some action like beep or begins a delegate.

Related