how to detect which key is pressed in javascript code example
Example 1: how to check if enter is pressed javascript
$('#usersearch').keydown(function(e){
if(e.keyCode === 13){
alert("Enter was pressed ");
}
});
Example 2: js when key is pressed
document.addEventListener("keypress", function(event) {
});
Example 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');
}
});