Skip to content
Related Articles

Related Articles

Improve Article

HTML DOM | KeyboardEvent altKey Property

  • Last Updated : 13 Feb, 2019

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.



Below program illustrates the KeyboardEvent altkey property in HTML:

Example: This example check whether the “ALT” key is pressed or not.

<!DOCTYPE html>
        HTML DOM KeyboardEvent altKey property
    <h2>KeyboardEvent altKey Property</h2>
        Check whether the alt key is pressed or not
    <input type="text" onkeydown="keyboard(event)">
    <p id = "test"></p>
    <!-- script to check alt key event -->
        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!";

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

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :