|
<STRONG><FONT size=2><FONT face=Arial><SPAN class=smalltxt twffan="done"><SPAN class=bold twffan="done">键盘事件全面控制</SPAN></SPAN><BR><BR></FONT></FONT></STRONG><SPAN style="FONT-SIZE: 12px" twffan="done"><HTML><BR><HEAD><BR><TITLE>Keyboard Event Handler Lab</TITLE><BR><STYLE TYPE="text/css"><BR>TD {text-align:center}<BR></STYLE><BR><SCRIPT LANGUAGE="java script"><BR>function init() {<BR> document.onkeydown = showKeyDown<BR> document.onkeyup = showKeyUp<BR> document.onkeypress = showKeyPress<BR>}<BR><BR>function showKeyDown(evt) {<BR> evt = (evt) ? evt : window.event<BR> document.getElementById("pressKeyCode").innerHTML = 0<BR> document.getElementById("upKeyCode").innerHTML = 0<BR> document.getElementById("pressCharCode").innerHTML = 0<BR> document.getElementById("upCharCode").innerHTML = 0<BR> restoreModifiers("")<BR> restoreModifiers("Down")<BR> restoreModifiers("Up")<BR> document.getElementById("downKeyCode").innerHTML = evt.keyCode<BR> if (evt.charCode) {<BR> document.getElementById("downCharCode").innerHTML = evt.charCode<BR> }<BR> showModifiers("Down", evt)<BR>}<BR>function showKeyUp(evt) {<BR> evt = (evt) ? evt : window.event<BR> document.getElementById("upKeyCode").innerHTML = evt.keyCode<BR> if (evt.charCode) {<BR> document.getElementById("upCharCode").innerHTML = evt.charCode<BR> }<BR> showModifiers("Up", evt)<BR> return false<BR>}<BR>function showKeyPress(evt) {<BR> evt = (evt) ? evt : window.event<BR> document.getElementById("pressKeyCode").innerHTML = evt.keyCode<BR> if (evt.charCode) {<BR> document.getElementById("pressCharCode").innerHTML = evt.charCode<BR> }<BR> showModifiers("", evt)<BR> return false<BR>}<BR>function showModifiers(ext, evt) {<BR> restoreModifiers(ext)<BR> if (evt.shiftKey) {<BR> document.getElementById("shift" + ext).style.backgroundColor = "#ff0000"<BR> }<BR> if (evt.ctrlKey) {<BR> document.getElementById("ctrl" + ext).style.backgroundColor = "#00ff00"<BR> }<BR> if (evt.altKey) {<BR> document.getElementById("alt" + ext).style.backgroundColor = "#0000ff"<BR> }<BR>}<BR>function restoreModifiers(ext) {<BR> document.getElementById("shift" + ext).style.backgroundColor = "#ffffff"<BR> document.getElementById("ctrl" + ext).style.backgroundColor = "#ffffff"<BR> document.getElementById("alt" + ext).style.backgroundColor = "#ffffff"<BR>}<BR></SCRIPT><BR></HEAD><BR><BR><BODY onLoad="init()"><BR><H1>Keyboard Event Handler Lab</H1><BR><HR><BR><FORM><BR><TABLE BORDER=2 CELLPADDING=2><BR><TR><TH></TH><TH>onKeyDown</TH><TH>onKeyPress</TH><TH>onKeyUp</TH></TR><BR><TR><TH>Key Codes</TH><BR> <TD ID="downKeyCode">0</TD><BR> <TD ID="pressKeyCode">0</TD><BR> <TD ID="upKeyCode">0</TD><BR></TR><BR><TR><TH>Char Codes (IE5/Mac; NN6)</TH><BR> <TD ID="downCharCode">0</TD><BR> <TD ID="pressCharCode">0</TD><BR> <TD ID="upCharCode">0</TD><BR></TR><BR><TR><TH ROWSPAN=3>Modifier Keys</TH><BR> <TD><SPAN ID="shiftDown">Shift</SPAN></TD><BR> <TD><SPAN ID="shift">Shift</SPAN></TD><BR> <TD><SPAN ID="shiftUp">Shift</SPAN></TD><BR></TR><BR><TR><BR> <TD><SPAN ID="ctrlDown">Ctrl</SPAN></TD><BR> <TD><SPAN ID="ctrl">Ctrl</SPAN></TD><BR> <TD><SPAN ID="ctrlUp">Ctrl</SPAN></TD><BR></TR><BR><TR><BR> <TD><SPAN ID="altDown">Alt</SPAN></TD><BR> <TD><SPAN ID="alt">Alt</SPAN></TD><BR> <TD><SPAN ID="altUp">Alt</SPAN></TD><BR></TR><BR></TABLE><BR></FORM><BR></BODY><BR></HTML></SPAN> <BR> |
|