Skip to content

Instantly share code, notes, and snippets.

@lingo
Forked from anonymous/checkArrowKeys.js
Last active June 6, 2017 08:51
Show Gist options
  • Save lingo/0c7afab81c2c3c12de8ed16cbe7f8b1e to your computer and use it in GitHub Desktop.
Save lingo/0c7afab81c2c3c12de8ed16cbe7f8b1e to your computer and use it in GitHub Desktop.
Animated Knots key handling
// document.onkeydown=checkArrowKeys;
document.addEventListener('keydown', checkArrowKeys);
function checkArrowKeys(e) {
var evt = e ? e : event;
var mykey = evt.keyCode;
if ((mykey == 37) && (prevKnot > 1)) {
showButtons(ButtonFadeDelay);
elemQ = document.getElementById('Prelim'); // Get Identity
elemQ.style.zIndex = -2; // Hide Labelled Image If Showing
nextImage(prevKnot, prevKnot - 1); // Previous Image
prevKnot--; // Decrease Count
reset();
e.preventDefault(); // inserted e.preventDefault() here
}
// Right Arrow Key (Up)
if ((mykey == 39) && (prevKnot < MaxImages)) {
showButtons(ButtonFadeDelay);
elemQ = document.getElementById('Prelim'); // Get Identity
elemQ.style.zIndex = -2; // Hide Labelled Image If Showing
nextImage(prevKnot, prevKnot + 1); // Previous Image
prevKnot++; // Decrease Count
reset();
e.preventDefault(); // inserted e.preventDefault() here
}
// Removed e.preventDefault() from here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment