Skip to content

Commit

Permalink
Fix bug that caused keys to be highlighted during a rerun
Browse files Browse the repository at this point in the history
Key events were being ignored after a time trial was cut off. If the
user was pressing a key right when the time was up, the key up event
would be ignored. This meant that the keyboard would remain in a state
wherein it would think a key was still being pressed when it actually
wasn't.
  • Loading branch information
rcjsuen committed Jan 15, 2016
1 parent 10283ff commit 645fabf
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,29 @@ function getEventKey(e) {

function keyUpHandler(e) {
var input = document.getElementById("input");
if (input.disabled) {
return;
}

if (e.keyCode === ASCII_SHIFT) {
shiftDown = false;
requestAnimationFrame(drawKeyboard);

if (input.disabled) {
requestAnimationFrame(drawKeyboard);
}
} else if (e.keyCode === ASCII_SPACEBAR) {
spaceDown = false;
requestAnimationFrame(drawKeyboard);
spaceDown = false;

if (input.disabled) {
requestAnimationFrame(drawKeyboard);
}
} else {
var key = getEventKey(e);

for (var i = 0; i < keyboard.length; i++) {
for (var j = 0; j < keyboard[i].length; j++) {
if (keyboard[i][j] === key) {
keyDown[i][j] = false;
requestAnimationFrame(drawKeyboard);

if (input.disabled) {
requestAnimationFrame(drawKeyboard);
}
return;
}
}
Expand Down

0 comments on commit 645fabf

Please sign in to comment.