Skip to content
Related Articles

Related Articles

JavaScript | MouseEvent shiftKey Property
  • Last Updated : 07 Jan, 2019

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 shift key is pressed or not.

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

Example :




<!DOCTYPE html>
<html>
    <head>
        <title>JavaScript Mouse Event</title>
    </head>
    <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>        
        <script>
        function geek (event) {
            if (event.shiftKey) {
                alert ("Shift key is pressed.");
            }
            else {
                alert ("Shift key is not pressed.");
            }
        }
        </script>
    </body>
</html>

Output:
Clicking button (Shift key is not pressed):
shiftkey
Clicking button (Shift key is pressed):
shiftkey

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

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

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :