|
||
DHTMLLib Demos/ Keys
Tracking key strokes is very easy. Just use the document's onkeypress
event and then retrieve the ASCII keyCode from the event object. In this
example we add support for quickly jumping to the top or bottom of the page
in response to the "T" or "B" keys.
This demonstration does not run on the Macintosh version of Internet Explorer. The Mac
version of Internet Explorer does not support the key events.
© 1998 by InsideDHTML.com, LLC. All rights reserved.
function doKeys() {
var key = (String.fromCharCode(window.event.keyCode).toUpperCase())
switch (key) {
case "T":
window.scrollTo(0,0)
break;
case "B":
window.scrollTo(0,document.body.scrollHeight - document.body.clientHeight)
break;
}
}
function doLoad() {
setup()
document.onkeypress = doKeys
}
window.onload = doLoad;
Macintosh Notes