微信

键盘事件-键代码编号

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>

  

posted @   Admin_info  阅读(471)  评论(0编辑  收藏  举报
编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法
青春时代是一个短暂的美梦,当你醒来时,这早已消失得无影无踪了。
点点Admin_info
点击右上角即可分享
微信分享提示