Skip to content

Instantly share code, notes, and snippets.

@euharrison
Last active October 5, 2015 01:54
Show Gist options
  • Save euharrison/a170a6cd1e221205e523 to your computer and use it in GitHub Desktop.
Save euharrison/a170a6cd1e221205e523 to your computer and use it in GitHub Desktop.
arrows key to calibrate
var values = [0,0,0,0];
document.addEventListener('keydown', function(e) {
if (!e.ctrlKey && !e.altKey && !e.shiftKey) {
switch (e.which) {
case 38: values[0]++; e.preventDefault(); break; //right
case 39: values[0]++; e.preventDefault(); break; //up
case 37: values[0]--; e.preventDefault(); break; //left
case 40: values[0]--; e.preventDefault(); break; //down
}
}
if (e.ctrlKey) {
switch (e.which) {
case 38: values[1]++; e.preventDefault(); break;
case 39: values[1]++; e.preventDefault(); break;
case 37: values[1]--; e.preventDefault(); break;
case 40: values[1]--; e.preventDefault(); break;
}
}
if (e.shiftKey) {
switch (e.which) {
case 38: values[2]++; e.preventDefault(); break;
case 39: values[2]++; e.preventDefault(); break;
case 37: values[2]--; e.preventDefault(); break;
case 40: values[2]--; e.preventDefault(); break;
}
}
if (e.altKey) {
switch (e.which) {
case 38: values[3]++; e.preventDefault(); break;
case 39: values[3]++; e.preventDefault(); break;
case 37: values[3]--; e.preventDefault(); break;
case 40: values[3]--; e.preventDefault(); break;
}
}
console.log(values);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment