Keyboard events are not part of DOM Level 1 or Level 2, but are still implemented in recent browsers. Accessing the events differs from the usual approach (window.event in Internet Explorer; the event as the automatic parameter of the function in all other browsers). But then, the keyCode property returns the ASCII code of the key, which can then be processed, as in the following code: Listening to Keyboard Events (key.html)
Figure 6.3 shows the result. The keys that are pressed are shown. Figure 6.3. The key pressed is shown.Note All characters in Figure 6.3 are shown in uppercase, since JavaScript always takes into consideration which key was pressed, not whether it was upper- or lowercase. You can, however, also find out whether special keys were pressed by taking a look at the altKey, ctrlKey, and shiftKey properties. |