The HTML KeyboardEvent which property returns the Unicode character code of the key that fires the onkeypress event, onkeydown event or onkeyup event in an HTML document.
Syntax
Following is the syntax −
event.which
Let us see an example of HTML KeyboardEvent which property −
Example
<!DOCTYPE html> <html> <style> body { color: #000; height: 100vh; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat; text-align: center; } input { border: 2px solid #fff; padding: 8px; background: transparent; width: 310px; border-radius: 20px; outline: none; } ::placeholder { color: #000; } .show { font-size: 1.2rem; color: #fff; } </style> <body> <h1>HTML KeyboardEvent which Property Demo</h1> <input type="text" placeholder="Enter your message" onkeypress="display(event)"> <div class="show"> <p>The above message in Unicode character is:</p> </div> <script> function display(event) { document.querySelector(".show").innerHTML += "<p>" + event.which + "</p>"; } </script> </body> </html>
Output
Now start typing your message in the text field and then see below the same message in the Unicode character −