Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading