Answers for "how to do a key press in javascript"

14

js when key is pressed

document.addEventListener("keypress", function(event) {
	// do stuff
});
Posted by: Guest on March-08-2020
3

js keyboard input

document.addEventListener('keydown', function(event) {
    if(event.keyCode == 37) {
        alert('Left was pressed');
    }
    else if(event.keyCode == 39) {
        alert('Right was pressed');
    }
});
Posted by: Guest on August-17-2020
0

adding event listener keypress event in javascript

let msg = document.getDocumentById('#message');

msg.addEventListener("keydown", (event) => {
    // handle keydown
});

msg.addEventListener("keypress", (event) => {
    // handle keypress
});

msg.addEventListener("keyup", (event) => {
    // handle keyup
});
Posted by: Guest on November-18-2020

Code answers related to "how to do a key press in javascript"

Browse Popular Code Answers by Language