January 19, 2001 - Detecting the CTRL Key
![]() |
January 19, 2001 Detecting the CTRL Key Tips: January 2001
Yehuda Shiran, Ph.D.
|
e object holds a lot of information about the Netscape 6 event. The ctrlKey property, for example, reveals whether the CTRL key was pressed during the event firing. Possible values are true and false. The following statement prints the ctrlKey property value to the status window:
window.status = e.ctrlKey;
The status window is shown on the bottom left corner of Netscape 6 window. Notice that you have to pass the e object as a parameter to those functions which reference it. In the following example, we pass the e object as a parameter to colorItTan():
<DIV ID="demoDiv" STYLE="position:relative; left:100px; top:20px; width:220px;
height:25px; color:blue; background-color:yellow;">Press the CTRL and click me with the left button!</DIV>
<SCRIPT LANGUAGE="JavaScript">
<!--
var demoObj;
function init() {
demoObj = document.getElementById("demoDiv");
demoObj.addEventListener("click", colorItTan, false);
}
function colorItTan(e) {
demoObj.style.backgroundColor = "tan";
window.status = e.ctrlKey;
}
onload = init;
// -->
</SCRIPT>
Get on Netscape 6 browser and play with this demo. Click the left button while CTRL is down. See the different values printed to the status window: true for CTRL key pressed, false otherwise.



