键盘事件-键代码编号
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > <title>键盘事件全面控制</title> <style type= "text/css" > td {text-align:center} </style> <script language= "javascript" > function init() { document.onkeydown = showKeyDown document.onkeyup = showKeyUp document.onkeypress = showKeyPress } function showKeyDown(evt) { evt = (evt) ? evt : window. event document.getElementById( "pressKeyCode" ).innerHTML = 0 document.getElementById( "upKeyCode" ).innerHTML = 0 document.getElementById( "pressCharCode" ).innerHTML = 0 document.getElementById( "upCharCode" ).innerHTML = 0 restoreModifiers( "" ) restoreModifiers( "Down" ) restoreModifiers( "Up" ) document.getElementById( "downKeyCode" ).innerHTML = evt.keyCode if (evt.charCode) { document.getElementById( "downCharCode" ).innerHTML = evt.charCode } showModifiers( "Down" , evt) } function showKeyUp(evt) { evt = (evt) ? evt : window. event document.getElementById( "upKeyCode" ).innerHTML = evt.keyCode if (evt.charCode) { document.getElementById( "upCharCode" ).innerHTML = evt.charCode } showModifiers( "Up" , evt) return false } function showKeyPress(evt) { evt = (evt) ? evt : window. event document.getElementById( "pressKeyCode" ).innerHTML = evt.keyCode if (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> </body> </html> |
人如代码,规矩灵活;代码如诗,字句精伦。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法