Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
JavaScript can also detect keyboard actions. The main event handler for this purpose is onKeyPress, which occurs when a key is pressed and released or held down. As with mouse buttons, you can detect the down and up parts of the keypress with the onKeyDown and onKeyUp event handlers.
Note
ASCII (American Standard Code for Information Interchange) is the standard numeric code used by most computers to represent characters. It assigns the numbers 0–128 to various characters—for example, the capital letters A through Z are ASCII values 65 to 90.
Of course, you might find it useful to know which key the user pressed. You can find this out with the event object, which is sent to your event handler when the event occurs. In Internet Explorer, event.keyCode stores the ASCII character code for the key that was pressed. In non-Internet Explorer browsers, the event.which property stores the ASCII character code for the key that was pressed.