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

Time:09-11

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

CodePudding user response:

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

  • Related