Home|Sitemap|Contact

How can you capture the down cursor key and perform some event?


Press the down cursor key.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">

<head>
<title>Down Cursor Key Capture</title>
<script type="text/javascript">
<!--
this.focus();

// capture the DOM key events for the three different DOMs (IE,NS 4,DOM2)
// DOM 2 (modern browsers)
if (document.addEventListener)
    document.addEventListener("keypress",checkKey,true);
// NS 4 (proprietary)
if (navigator.appName == "Netscape" && navigator.appVersion.indexOf("4.x") != -1)
    document.captureEvents(Event.KEYPRESS);
// (IE proprietary)
document.onkeyup=checkKey;


// the function called on the DOM key events
function checkKey(e) {
    // get the key code - 40 is the down cursor arrow
    var tmp = (window.event) ? event.keyCode : e.keyCode;
    if (tmp==40)
        alert('Down Cursor Key Pressed');
}
//-->
</script>
</head>

<body>
Press the down cursor key.
</body>

</html>