In This Javascript Tutorial we will See How To Trigger Key To Check Which Keyboard key Is Pressed On KeyPress,KeyDown Event using JS And Netbeans Editor .
Project Source Code:
<!DOCTYPE html>
<html>
<head>
<title>Key Enter - SPACE - UP - DOWN - RIGHT - LEFT</title>
<meta charset="windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body onkeypress="triggerKey(event)">
<script>
function triggerKey(event)
{
var code = event.keyCode;
// up down left right work on keydown
switch(code){
case 37:
console.log("LEFT");
break;
case 38:
console.log("UP");
break;
case 39:
console.log("RIGHT");
break;
case 40:
console.log("DOWN");
break;
}
console.log(code);
/*
if(code == 13)
{
console.log("ENETER");
}
else if(code == 32)
{
console.log("SPACEBAR");
}*/
}
</script>
</body>
</html>
Get More Projects Source Code