onKeyDown (Event handler)

Triggered when a key is pressed.

Availability:

HTML version - 4.0
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Opera browser - 3.0
Property/method value type:Boolean primitive
JavaScript syntax:-myObject.onkeydown = aHandler
HTML syntax:<A onKeyDown="..."> <AREA onKeyDown="..."> <BODY onKeyDown="..."> <HTMLTag onKeyDown="..."> <IMG onKeyDown="..."> <INPUT onKeyDown="...">
Argument list:aHandlerA reference to a function object to handle the event

As the key is pressed down, this event is triggered. If you return the value true, the event will be passed to the browser for further processing. Returning false inhibits this action and discards the message.

In Netscape, the key code of the key that triggered the event is available in the which property of the Event object that is passed to the event handler as an argument. The equivalent value in MSIE is available in the keyCode property of the event object referenced by the window.event property.

The key value is the Unicode character code point value, which is a numeric value. This may need to be converted to a character if you want to display it. You can do that with the String.fromCharCode() static method, which will create a one character string for you.

You may need to determine whether any of the modifier keys were pressed. In Netscape, you retrieve a bitmask value from the modifiers property of the Event object. This can then be masked against the various bit flags available as static properties of the Event class.

In MSIE, modifier keys are available with a set of properties, which return the state of each modifier key individually.

In MSIE, you can modify the value of the key that is passed back to the browser by storing a different Unicode code point value in the returnValue property of the Event object.

Warnings:

See also:Element object, Event, Event handler, Event model, Event names, Event object, Event.altKey, Event.ctrlKey, Event.keyCode, Event.modifiers, Event.returnValue, Event.shiftKey, Event.which, Handler, JellyScript, Keyboard events, onKeyPress, onKeyUp, Semantic event, String.fromCharCode(), TEXTAREA object, TextCell object

Supported by objects:

A

ACRONYM

ADDRESS

Anchor

APPLET

AREA

B

BIG

BLOCKQUOTE

BODY

BUTTON

CAPTION

CENTER

Checkbox

CITE

CODE

DD

DEL

DFN

DIR

DIV

DL

Document

DT

EM

FIELDSET

FileUpload

FONT

FORM

H1

HR

I

IMG

Input

INS

KBD

LABEL

LEGEND

LI

LISTING

MAP

MARQUEE

MENU

OL

P

Password

PLAINTEXT

PRE

Q

RadioButton

ResetButton

S

SAMP

Select

SMALL

SPAN

STRIKE

STRONG

SUB

SubmitButton

SUP

TABLE

TBODY

TD

TEXTAREA

TextCell

TFOOT

TH

THEAD

TR

TT

U

UL

Url

VAR