Answers for "how to get which key is pressed in javascript"

13

js when key is pressed

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

how to get which key is pressed in javascript

function myKeyPress(e){
  var keynum;

  if(window.event) { // IE                  
    keynum = e.keyCode;
  } else if(e.which){ // Netscape/Firefox/Opera                 
    keynum = e.which;
  }

  alert(String.fromCharCode(keynum));
}
Posted by: Guest on August-10-2021

Code answers related to "how to get which key is pressed in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language