MouseEvent ctrlKey Property - Javascript DOM

Javascript examples for DOM:Mouse Event

Description

The ctrlKey property tells if "CTRL" key was pressed when a mouse event was triggered.

This property is read-only.

Return Value

A Boolean, indicating if the "CTRL" key was pressed when the mouse event occured.

The following code shows how to find out whether or not the "CTRL" key was pressed when a mouse button is clicked:

Demo Code

ResultView the demo in separate window

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

<p>Click somewhere in the document. </p>

<script>
function isKeyPressed(event) {/*from ww w .j ava 2 s  .c  o  m*/
    if (event.ctrlKey) {
        console.log("The CTRL key was pressed!");
    } else {
        console.log("The CTRL key was NOT pressed!");
    }
}
</script>

</body>
</html>

Related Tutorials