The HTML DOM KeyboardEvent metaKey property returns the Boolean value (true/false) corresponding to if meta key was pressed using an event or not.
Syntax
Following is the syntax −
Returning booleanValue −
event.metaKey
Example
Let us see an example for KeyboardEvent metaKey property −
<!DOCTYPE html> <html> <head> <title>KeyboardEvent metaKey</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>KeyboardEvent-metaKey</legend> <label>Editor: <input type="text" id="textSelect" onkeydown="getEventData(event)" autocomplete="off"> </label> <div id="divDisplay">I Dare you to press the meta key</div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var textSelect = document.getElementById("textSelect"); function getEventData(InputEvent) { if(InputEvent.metaKey === true) divDisplay.textContent = 'You are very brave!'; else divDisplay.textContent = 'You scared enough?'; } </script> </body> </html>
Output
This will produce the following output −
Before typing anything in the text field −
After typing wrong answer in the text field −
After typing correct answer in the text field −