MouseEvent shiftKey Property - Javascript DOM

Javascript examples for DOM:Mouse Event

Description

The shiftKey property indicates if the "SHIFT" key was pressed.

This property is read-only.

Return Value

A Boolean, indicating whether the "SHIFT" key was pressed.

The following code shows how to find out whether or not the "SHIFT" key was pressed.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body onmousedown="isKeyPressed(event)">

<script>
function isKeyPressed(event) {//w w  w .j  a  v  a 2  s  .c o  m
    if (event.shiftKey) {
        console.log("The SHIFT key was pressed!");
    } else {
        console.log("The SHIFT key was NOT pressed!");
    }
}
</script>

</body>
</html>

Related Tutorials