get input from keyboard javascript code example
Example 1: js when key is pressed
document.addEventListener("keypress", function(event) {
// do stuff
});
Example 2: 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');
}
});