The onkeydown event

It’s handy to allow users to control your Web page via their keyboard as well as via their mouse. With the key event handlers, you can trigger events to happen when the appropriate keys are pressed. In Scripts 9.20 and 9.21, a standard slideshow (otherwise identical to the one in Script 4.17) can be viewed by pressing the left and right arrow keys on the keyboard (Figure 9.9).

Figure 9.9. This slideshow is controlled with keypresses, rather than mouse clicks on navigation buttons.

1.
document.onkeydown = keyHit;
Here we register the keyHit() function as the one to handle onkeydown events.
2.
var thisPic = 0;
The variable ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.