1//detecting arrow key presses
2document.addEventListener('keydown', function(e) {
3 switch (e.keyCode) {
4 case 37:
5 alert('left');
6 break;
7 case 38:
8 alert('up');
9 break;
10 case 39:
11 alert('right');
12 break;
13 case 40:
14 alert('down');
15 break;
16 }
17});