Answers for "function to count arrow keypress in js"

4

javascript detect arrow key press

//detecting arrow key presses
document.addEventListener('keydown', function(e) {
    switch (e.keyCode) {
        case 37:
            alert('left');
            break;
        case 38:
           alert('up');
            break;
        case 39:
            alert('right');
            break;
        case 40:
            alert('down');
            break;
    }
});
Posted by: Guest on August-05-2019

Code answers related to "Javascript"

Browse Popular Code Answers by Language