C# arrow key input for a console app

前端 未结 5 1225
一生所求
一生所求 2020-11-28 14:29

I have a simple console app written in C#. I want to be able to detect arrow key presses, so I can allow the user to steer. How do I detect keydown/keyup events with a con

5条回答
  •  没有蜡笔的小新
    2020-11-28 15:03

    you can do this

    bool keyWasPressed = false;
    if (consolekey.avalable)
    {
    keyvar = console.readkey(true);
    keyWasPressed = true;
    }
    if(keyWasPressed)
    {
    //enter you code here using keyvar
    }
    else
    {
    //the commands that happen if you don't press anything
    }
    

提交回复
热议问题