November 14, 2000 - Probing the Left CTRL Key | WebReference

November 14, 2000 - Probing the Left CTRL Key

Yehuda Shiran November 14, 2000
Probing the Left CTRL Key
Tips: November 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Starting with IE 5.5, you can set and retrieve the status of the left CTRL key. You can detect its status by probing event.ctrlLeft. It is true when the key is pressed, false otherwise. You can also set event.ctrlLeft.

Currently, this property is supported only by Windows NT and 2000. If you try this on Windows 95/98, the response will be as if the right CTRL key is pressed.

You have to make sure that the document has focus, which you do by calling document.body.focus().

Try pressing the left CTRL key. You will get an alert, showing the pressed key. You should get "Right CTRL Pressed" on Windows 95/98 and "Left CTRL Pressed" on NT and Windows 2000. To facilitate this demo, we modified the BODY statement of this tip as follows:

<BODY onload="document.body.focus();" onkeydown="ctrlDown();">

The event handler is defined as:

function ctrlDown() {
    if (event.ctrlLeft) {
      alert("Left CTRL Pressed");
    else {
      if (event.ctrlKey) {
        alert("Right CTRL Pressed");

Read more about events and event handling in Column 11, The Cross-Browser Event Model.