Keyboard handler is triggered multiple times.
svdsande opened this issue · 0 comments
Due to the fact that both key and code are checked when determining if a key is triggered, a keyboard handler could be called multiple times.
The following function will be called twice when pressing NumpadEnter
@onKey('Enter')
@onKey('NumpadEnter')
onEnterOrNumpadEnterDown(e) {
this.args.onTrigger(e);
}
The reason for this behavior is the fact that in this scenario event.code
is equal to NumpadEnter
but event.key
is equal to Enter
Therefore when iterating over all keyboard handlers @onKey('Enter')
will also be called since event.key
will match. I found an older pull request #135 in which the option is discussed the specify a mode, this would enable developers to explicitly specify state if the they want to match based on key or code. Having this option would solve the problem at hand, but I understand that this proposal didn't make it in the final API design. But would it be possible to combine @onKey('Enter')
and @onKey('NumpadEnter')
? Let me know if I could help in any way.