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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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");

      }
    }
	document.body.focus();
}

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


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business