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

243 Views Asked by At

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);
    }
1

There are 1 best solutions below

0
Mordagel On BEST ANSWER

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