October 21, 2000 - Probing the Left ALT Key | WebReference

October 21, 2000 - Probing the Left ALT Key

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

Yehuda Shiran, Ph.D.
Doc JavaScript

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

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