Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>Keyboard Events</h1> <h2>The code Property</h2> <p>Press a keyboard key in the input field:</p> <input type="text" size="40" onkeypress="myFunction(event)"> <p>The code property returns the name of the key you pressed:</p> <p id="demo"></p> <script> function myFunction(event) { let key = event.code; document.getElementById("demo").innerHTML = key; } </script> </body> </html>