Open In App

JavaScript MouseEvent shiftKey Property

Last Updated : 08 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The mouseEvent shiftKey property is used to define whether the shift key is pressed or not. It is a boolean value. When the shift key is pressed then on click of the mouse left button, it returns true and if the shift key is not pressed then it returns false. 

Syntax:

event.shiftKey

Return Value: It returns a boolean value indicating whether the shift key is pressed or not.

  • true: it indicates the shift key is pressed.
  • false: it indicates the shift key is not pressed.

Example: In this example, we will see the example of MouseEvent shiftKey property.

html




<body style="text-align:center;">
  
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
  
    <h2>
        mouseEvent shiftKey Property
    </h2>
  
    <button onclick="geek (event);">Get Shift key state!</button>
    <p id="gfg"></p>
    <script>
        function geek (event) {
            if (event.shiftKey) {
                document.getElementById("gfg").innerHTML= "Shift key is pressed.";
            }
            else {
                document.getElementById("gfg").innerHTML= "Shift key is not pressed.";
            }
        }
    </script>
</body>


Output:

JavaScript MouseEvent shiftKey Property

JavaScript MouseEvent shiftKey Property

Supported Browsers: The browser supported by shiftKey properties are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads