key 13 keycode is for ENTER the key. Using onkeypress can get the key code and name.
Read: JavaScript keycode list
Get event keycode 13 in JavaScript
HTML example code, ENTER keypress event. If the user presses the enter key then an alert box will show.
<!DOCTYPE html>
<html>
<body>
<input type="text" id="myInput">
<script>
document.onkeypress = function(event) {
if (event.which == 13) {
alert(event.code + " " + event.which);
}
}
</script>
</body>
</html>
Output:
Or use window object
window.onkeypress = function(event) {
if (event.which == 13) {
alert(event.code + " " + event.which);
}
}
Do comment if you have any doubts and suggestions on this JS keycode example.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Wheather the key is F12???