0

I want the program to exit when I press Escape, the way it is right now, just close whenever a press anybutton.

Here is my code

game.KeyPress += (sender, e) => { game.Exit(); };

I using https://github.com/ppy/osuTK this as reference in my project. Both KeyPress and KeyPressEventArgs Inherit from osuTK.Input

There is also this code bellow

Key.Escape

The Key also Inherit from osuTK.Input.

game.KeyPress<KeyPressEventArgs<Key.Escape>> += (sender, e) => { game.Exit(); };

This code above doesn't work, but something close to that would be perfect.

2 Answers2

0

KeyPressEventArgs has the KeyChar property. Use that to test what key was pressed:

if (e.KeyChar == (char)Keys.Return)
{
    e.Handled = true;
}
Christo
  • 292
  • 1
  • 7
0

You can try with this code according to KeyPressEventArgs.KeyChar:

game.KeyPress += (sender, eventArgs) => {
    if (eventArgs.KeyChar == (char)Keys.Escape) {
        // TODO
    }
};
Nguyen Thanh
  • 91
  • 1
  • 7