Availability: |
| |||||||
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: | aHandler | A 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.
To use key-codes and modifier keys in a portable way, you will need to implement some browser-specific support and then call an appropriate routine according to the browser the script is executing in.
This is not supported on the WebTV platform.
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
Prev | Home | Next |
onHelp | Up | onKeyPress |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |