Pressing a key and then executing another key

I would like to write a small application using C #. When the user presses any key, this program binds.

For example, I press Q, then my application works with Triple Q.

thank

+3


source to share


1 answer


You can implement it without a timer, for example these codes:



static void Main(string[] args)
{
    var time = 3;
    char myKey = 'q';

    // do some things ...

    var key = Console.ReadKey().KeyChar;

    if (key == myKey)
    {
        bool ok = true;
        for (int count = 0; count < time; count++)
        {
            key = Console.ReadKey().KeyChar;
            if (key != myKey)
            {
                ok = false;
                break;
            }
        }

        if (ok)
        {
            // do my work
        }
        else
        {
            // Do some else works ...
        }
    }
    else
    {
        // Do some else works ...
    }


    Console.ReadKey();
}

      

+1


source







All Articles