Archive for December, 2007

Windows 2003 server web - 767Chapter 25Event Objectsbodyelement, which is the element that

Thursday, December 27th, 2007

767Chapter 25Event Objectsbodyelement, which is the element that caught the first mouse event to register itself as thetoElementfor the center table cell. Related Items:srcElementproperty. keyCodeValue:Integer.Read-OnlyCompatibility:WinIE4+, MacIE4+, NN6+, Moz1+, Safari1+ For keyboard events, the keyCodeproperty returns an integer corresponding to the Unicodevalue of the character (for onkeypressevents) or the keyboard character key (for onkey- downand onkeyupevents). There is a significant distinction between these numbering codesystems. If you want the Unicode values (the same as ASCII values for the Latin character set) for thekey that a user pressed, get the keyCodeproperty from the onkeypressevent handler. Forexample, a lowercase a returns 97, while an uppercase A returns 65. Non-character keys, such as arrows, page navigation, and function keys, return a nullvalue for the keyCodeprop- erty during onkeypressevents. In other words, the keyCodeproperty for onkeypresseventsis more like a character code than a key code. To capture the exact keyboard key that the user presses, use either the onkeydownoronkeyupevent handler. For these events, the eventobject captures a numeric code associ- ated with a particular key on the keyboard. For the character keys, this varies with the lan- guage assigned as the system language. Importantly, there is no distinction betweenuppercase or lowercase: The A key on the Latin keyboard returns a value of 65, regardlessof the state of the Shift key. At the same time, however, the press of the Shift key fired its ownonkeydownand onkeyupevents, setting the keyCodevalue to 16. Other non-character keys arrows, page navigation, function, and similar have their own codes as well. This gets verydetailed, including special key codes for the numeric keyboard keys that are different fromtheir corresponding numbers along the top row of the alphanumeric keyboard. Be sure to see the extensive section on keyboard events in Chapter 15 for examples of how toapply the keyCodeproperty in applications. ExampleListing 25-16 provides an additional play area to view the keyCodeproperty for all three key- board events while you type into a textarea. You can use this page later as an authoring toolto grab the precise codes for keyboard keys you may not be familiar with. Listing 25-16:Displaying keyCode Property Values