Created
November 8, 2020 11:06
-
-
Save lewdev/d688442a844dbda2ae9f3a52679a1eb4 to your computer and use it in GitHub Desktop.
Which key has been pressed in JavaScript / HTML.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
My StackOverflow answer to "How to find out what character key is pressed?": | |
https://stackoverflow.com/a/51955727/1675237 | |
--> | |
<table> | |
<tr><td>Key:</td><td id="key"></td></tr> | |
<tr><td>Key Code:</td><td id="keyCode"></td></tr> | |
<tr><td>Event Code:</td><td id="eventCode"></td></tr> | |
</table> | |
<script type="text/javascript"> | |
window.addEventListener("keydown", function (e) { | |
//tested in IE/Chrome/Firefox | |
document.getElementById("key").innerHTML = e.key; | |
document.getElementById("keyCode").innerHTML = e.keyCode; | |
document.getElementById("eventCode").innerHTML = e.code; | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment