HTML DOM | KeyboardEvent altKey Property
The KeyboardEvent altKey property in HTML DOM is a read-only property and used to return the boolean value which indicates the alt key is pressed or not. It returns True if alt key is pressed otherwise return false.
Syntax:
event.altKey
Below program illustrates the KeyboardEvent altkey property in HTML:
Example: This example check whether the “ALT” key is pressed or not.
<!DOCTYPE html> <html> <head> <title> HTML DOM KeyboardEvent altKey property </title> </head> <body> <h1>GeeksforGeeks</h1> <h2>KeyboardEvent altKey Property</h2> <p> Check whether the alt key is pressed or not </p> <input type="text" onkeydown="keyboard(event)"> <p id = "test"></p> <!-- script to check alt key event --> <script> function keyboard(event) { var a = document.getElementById("test"); if (event.altKey) { a.innerHTML = "The ALT key has been pressed!"; } else { a.innerHTML = "The ALT key has not been pressed!"; } } </script> </body> </html> |
Output:
Before Press the Key:

After Press the key:

Supported Browsers: The browser supported by KeyboardEvent altKey property are listed below:
- Opera
- Internet Explorer
- Google Chrome
- Firefox
- Apple Safari
Recommended Posts:
- HTML | DOM TouchEvent altKey Property
- HTML | DOM KeyboardEvent key Property
- HTML | KeyboardEvent which Property
- HTML | DOM keyboardEvent charCode Property
- HTML | DOM KeyboardEvent keyCode Property
- HTML | DOM KeyboardEvent location Property
- HTML | DOM KeyboardEvent code Property
- HTML | DOM KeyboardEvent metaKey Property
- HTML | DOM KeyboardEvent shiftKey Property
- Javascript | MouseEvent altKey Property
- HTML | DOM KeyboardEvent
- HTML | DOM KeyboardEvent getModifierState() Method
- HTML | DOM li value Property
- HTML | DOM name Property
- HTML | DOM Map name Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


