Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 9a6bcdb

Browse files
MonoidMusicianpaf31
authored andcommitted
Ensure no duplicate keys (#24)
When a key is held down such that the OS sends repeats, "keydown" will be called before "keyup", so we need to ensure that the key is not present in the array before inserting it.
1 parent a16e1a8 commit 9a6bcdb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/FRP/Event/Keyboard.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
var currentKeys = [];
44
addEventListener("keydown", function(e) {
5-
currentKeys.push(e.keyCode);
5+
var index = currentKeys.indexOf(e.keyCode);
6+
if (index < 0) {
7+
currentKeys.push(e.keyCode);
8+
}
69
});
710
addEventListener("keyup", function(e) {
811
var index = currentKeys.indexOf(e.keyCode);

0 commit comments

Comments
 (0)