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
keyPress
events, because the "initial delay" depends on the operating system configuration! In fact,keyPress
events may not even fire repetitively.What you need to do is to listen to
keyDown
andkeyUp
events. 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
A
key pressing.