Javascript鍵盤事件全面控制

來源:互聯網
上載者:User
<STYLE TYPE="text/css">TD {text-align:center}</STYLE><SCRIPT LANGUAGE="JavaScript">function init() {document.onkeydown = showKeyDowndocument.onkeyup = showKeyUpdocument.onkeypress = showKeyPress}function showKeyDown(evt) {evt = (evt) ? evt : window.eventdocument.getElementById("pressKeyCode").innerHTML = 0document.getElementById("upKeyCode").innerHTML = 0document.getElementById("pressCharCode").innerHTML = 0document.getElementById("upCharCode").innerHTML = 0restoreModifiers("")restoreModifiers("Down")restoreModifiers("Up")document.getElementById("downKeyCode").innerHTML = evt.keyCodeif (evt.charCode) {document.getElementById("downCharCode").innerHTML = evt.charCode}showModifiers("Down", evt)}function showKeyUp(evt) {evt = (evt) ? evt : window.eventdocument.getElementById("upKeyCode").innerHTML = evt.keyCodeif (evt.charCode) {document.getElementById("upCharCode").innerHTML = evt.charCode}showModifiers("Up", evt)return false}function showKeyPress(evt) {evt = (evt) ? evt : window.eventdocument.getElementById("pressKeyCode").innerHTML = evt.keyCodeif (evt.charCode) {document.getElementById("pressCharCode").innerHTML = evt.charCode}showModifiers("", evt)return false}function showModifiers(ext, evt) {restoreModifiers(ext)if (evt.shiftKey) {document.getElementById("shift" + ext).style.backgroundColor = "#ff0000"}if (evt.ctrlKey) {document.getElementById("ctrl" + ext).style.backgroundColor = "#00ff00"}if (evt.altKey) {document.getElementById("alt" + ext).style.backgroundColor = "#0000ff"}}function restoreModifiers(ext) {document.getElementById("shift" + ext).style.backgroundColor = "#ffffff"document.getElementById("ctrl" + ext).style.backgroundColor = "#ffffff"document.getElementById("alt" + ext).style.backgroundColor = "#ffffff"}</SCRIPT></HEAD><BODY onLoad="init()"><H1>Keyboard Event Handler Lab</H1><HR><FORM><TABLE BORDER=2 CELLPADDING=2><TR><TH></TH><TH>onKeyDown</TH><TH>onKeyPress</TH><TH>onKeyUp</TH></TR><TR><TH>Key Codes</TH><TD ID="downKeyCode">0</TD><TD ID="pressKeyCode">0</TD><TD ID="upKeyCode">0</TD></TR><TR><TH>Char Codes (IE5/Mac; NN6)</TH><TD ID="downCharCode">0</TD><TD ID="pressCharCode">0</TD><TD ID="upCharCode">0</TD></TR><TR><TH ROWSPAN=3>Modifier Keys</TH><TD><SPAN ID="shiftDown">Shift</SPAN></TD><TD><SPAN ID="shift">Shift</SPAN></TD><TD><SPAN ID="shiftUp">Shift</SPAN></TD></TR><TR><TD><SPAN ID="ctrlDown">Ctrl</SPAN></TD><TD><SPAN ID="ctrl">Ctrl</SPAN></TD><TD><SPAN ID="ctrlUp">Ctrl</SPAN></TD></TR><TR><TD><SPAN ID="altDown">Alt</SPAN></TD><TD><SPAN ID="alt">Alt</SPAN></TD><TD><SPAN ID="altUp">Alt</SPAN></TD></TR></TABLE></FORM>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.