Vilda
Vilda

Reputation: 1793

Dart KeyboardEvent return false

I'm handeling Input in my framework the following way:

window.onKeyDown.listen((KeyboardEvent e) {
    _keys[e.keyCode]=true;
    e.stopPropagation();
});

(The whole class here)

I was used to put return false; at the end of my methods in Java which would indicate, that the event was taken care of. I've read that e.stopPropagation(); should do the same thing. Unfortunately it does not.

(Try pressing space in this sample game)

The question is, how to prevent the KeyboardEvent from going through the whole document.

Upvotes: 1

Views: 110

Answers (1)

Juan Mellado
Juan Mellado

Reputation: 15113

The preventDefault method could make the trick here:

window.onKeyDown.listen((KeyboardEvent e) {
...
  e.preventDefault();
});

Upvotes: 2

Related Questions