KeyEvent ctrlKey Property - Javascript DOM

Javascript examples for DOM:Key Event

Description

The ctrlKey property indicates if the "CTRL" key was pressed.

This property is read-only.

Return Value

A Boolean, indicating if the "CTRL" key was pressed.

The following code shows how to find out if the "CTRL" key was pressed:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="text" onkeydown="isKeyPressed(event)">

<p id="demo"></p>

<script>
function isKeyPressed(event) {/*w w w .ja  va2  s .  c om*/
    var x = document.getElementById("demo");
    if (event.ctrlKey) {
        x.innerHTML = "The CTRL key was pressed!";
    } else {
        x.innerHTML = "The CTRL key was NOT pressed!";
    }
}
</script>

</body>
</html>

Related Tutorials