Skip to content

Instantly share code, notes, and snippets.

@oddstr13
Created May 8, 2019 01:12
Show Gist options
  • Save oddstr13/d0e71ef5ded8cef56566b373bde1317a to your computer and use it in GitHub Desktop.
Save oddstr13/d0e71ef5ded8cef56566b373bde1317a to your computer and use it in GitHub Desktop.
define(['inputmanager'], function(inputmanager) {
'use strict';
console.log("keyboardnavigation");
document.addEventListener('keydown', function(e) {
console.log(e);
console.log(e.code);
console.log(e.key);
console.log(e.view);
console.log(e.which);
console.log(e.keyCode);
var capture = true;
switch (e.keyCode) {
case 37: // ArrowLeft
inputmanager.handle('left');
break;
case 38: // ArrowUp
inputmanager.handle('up');
break;
case 39: // ArrowRight
inputmanager.handle('right');
break;
case 40: // ArrowDown
inputmanager.handle('down');
break;
default:
capture = false;
}
if (capture) {
console.log("Disabling default event handling");
e.preventDefault();
}
});
return {};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment