You are here: Reference > JavaScript > client-side > event handling > properties > ctrlLeft (event)

ctrlLeft property (event)

Browser support:
Sets or retrieves whether the left CTRL key was down at the time when the event occurred.
If it is not necessary to know which CTRL key was pressed, use the cross-browser ctrlKey property.
For ALT and SHIFT keys, use the (altKey, altLeft) and (shiftKey, shiftLeft) properties.
Note that Internet Explorer from version 9 started to support different event objects similarly to Firefox, Opera, Google Chrome and Safari. The event object passed to an event handler and the event object referred to by the window.event property are different in Internet Explorer from version 9 (except if the event handler is registered with the attachEvent method). The ctrlLeft property is only supported by the window.event object.

Syntax:

object.ctrlLeft;
You can find the related objects in the Supported by objects section below.
The ctrlLeft property is read-only, except if the event object is created with the createEventObject method when it is read/write.

Possible values:

Boolean, one of the following values:
false
Left CTRL key is up.
true
Left CTRL key is down.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the ctrlLeft property:
<head>
    <script type="text/javascript">
        function GetCtrlState (event) {
            if (event.ctrlKey) {
                    // window.event and event differ in IE9 !!!
                if (window.event && 'ctrlLeft' in window.event) {
                    if (window.event.ctrlLeft) {
                        alert ("Left Ctrl key is down.");
                    }
                    else {
                        alert ("Right Ctrl key is down.");
                    }
                }
                else {
                    alert ("Ctrl key is down.");
                }
            }
            else {
                alert ("Ctrl key is up.");
            }
        }
    </script>
</head>
<body>
    Press and hold down the left or right CTRL key before you click on the button.
    <br />
    <button onclick="GetCtrlState (event);">Get Ctrl keys state!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content