I know that you can listen to key press and down events with Dart like:
var el = query('#el');
el.on.keyDown.add((e) {});
But the problem here is that it fires only once. I want repetition.
So, I tried keyPress instead, but it has a slight delay before the repetition. I am working on a game and I want it to fire instantly and repetitively.
First of all, don’t listen to
keyPressevents, because the “initial delay” depends on the operating system configuration! In fact,keyPressevents may not even fire repetitively.What you need to do is to listen to
keyDownandkeyUpevents. You can make a helper for this.Then depending on what you do in your game, you probably have “a game loop” of some sort, in your
update()method that gets called in every once in a while:Now your game loop checks repetitively for
Akey pressing.