spacer
Yehuda Shiran October 21, 2000
Probing the Left ALT Key
Tips: October 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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

This property is currently supported only in NT and Windows 2000. When you try it in Windows 95/98, the response will be as if the Right ALT key is pressed.

You have to make sure that the document has focus. You can make sure of it by calling document.body.focus().

Try pressing the Left ALT key. You will get an alert, showing the pressed key. You should get altRight on Windows 95/98 and altLeft on NT and Windows 2000. To facilitate this demo we modified the BODY statement of this tip to look like this:

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

The event handler is defined as:

function AltDown() {
  if (event.altLeft) {
    alert("altLeft Pressed");
  }
  else {
    if (event.altKey) {
      alert("altRight 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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint