【转】keyCode对照表及示例
程序员文章站
2024-03-17 11:59:58
...
由于对照表比较长,故先看两个示例:
1、获得任意键值
<html>
<!--请按任意键,你将得到该键的键值!-->
<body onkeypress=alert(event.keyCode )>
</body>
</html>
2、显示键值及其实际值
<html>
<head>
<script language="javascript">
ns4 = (document.layers) ? true : false;
ie4 = (document.all) ? true : false;
function keyDown(e){
if(ns4){
var nkey=e.which;
var iekey='现在是ns浏览器';
var realkey=String.fromCharCode(e.which);
}
if(ie4){
var iekey=event.keyCode;
var nkey='现在是ie浏览器';
var realkey=String.fromCharCode(event.keyCode );
if(event.keyCode ==32){realkey='\' 空格\''}
if(event.keyCode ==13){realkey='\' 回车\''}
if(event.keyCode ==27){realkey='\' Esc\''}
if(event.keyCode ==16){realkey='\' Shift\''}
if(event.keyCode ==17){realkey='\' Ctrl\''}
if(event.keyCode ==18){realkey='\' Alt\''}
}
alert('ns浏览器中键值:'+nkey+'\n'+'ie浏览器中键值:'+iekey+'\n'+'实际键为'+realkey);
}
document.onkeydown = keyDown;
if(ns4){
document.captureEvents(Event.KEYDOWN);
}
</script>
</head>
<body>
//Javascript Document.
<hr>
<center>
<h3>请按任意一个键。。。</h3>
</center>
</body>
</html>
keyCode对照表
keyCode | 键值 | keyCode | 键值 | |
0 | 128 | F17 | ||
1 | 129 | F18 | ||
2 | 130 | F19 | ||
3 | 131 | F20 | ||
4 | 132 | F21 | ||
5 | 133 | F22 | ||
6 | 134 | F23 | ||
7 | 135 | F24 | ||
8 | Backspace Backspace | 136 | Num_Lock | |
9 | Tab Tab | 137 | Scroll_Lock | |
10 | 138 | |||
11 | 139 | |||
12 | Clear | 140 | ||
13 | Enter | 141 | ||
14 | 142 | |||
15 | 143 | |||
16 | Shift_L | 144 | ||
17 | Control_L | 145 | ||
18 | Alt_L | 146 | ||
19 | Pause | 147 | ||
20 | Caps_Lock | 148 | ||
21 | 149 | |||
22 | 150 | |||
23 | 151 | |||
24 | 152 | |||
25 | 153 | |||
26 | 154 | |||
27 | Escape Escape | 155 | ||
28 | 156 | |||
29 | 157 | |||
30 | 158 | |||
31 | 159 | |||
32 | space space | 160 | ||
33 | Prior | 161 | ||
34 | Next | 162 | ||
35 | End | 163 | ||
36 | Home | 164 | ||
37 | Left | 165 | ||
38 | Up | 166 | ||
39 | Right | 167 | ||
40 | Down | 168 | ||
41 | Select | 169 | ||
42 | 170 | |||
43 | Execute | 171 | ||
44 | 172 | |||
45 | Insert | 173 | ||
46 | Delete | 174 | ||
47 | Help | 175 | ||
48 | 0 equal braceright | 176 | ||
49 | 1 exclam onesuperior | 177 | ||
50 | 2 quotedbl twosuperior | 178 | ||
51 | 3 section threesuperior | 179 | ||
52 | 4 dollar | 180 | ||
53 | 5 percent | 181 | ||
54 | 6 ampersand | 182 | ||
55 | 7 slash braceleft | 183 | ||
56 | 8 parenleft bracketleft | 184 | ||
57 | 9 parenright bracketright | 185 | ||
58 | 186 | |||
59 | 187 | acute grave | ||
60 | 188 | comma semicolon | ||
61 | 189 | minus underscore | ||
62 | 190 | period colon | ||
63 | 191 | |||
64 | 192 |
numbersign apostrophe |
||
65 | a A | 193 | ||
66 | b B | 194 | ||
67 | c C | 195 | ||
68 | d D | 196 | ||
69 | e E EuroSign | 197 | ||
70 | f F | 198 | ||
71 | g G | 199 | ||
72 | h H | 200 | ||
73 | i I | 201 | ||
74 | j J | 202 | ||
75 | k K | 203 | ||
76 | l L | 204 | ||
77 | m M mu | 205 | ||
78 | n N | 206 | ||
79 | o O | 207 | ||
80 | p P | 208 | ||
81 | q Q at | 209 | ||
82 | r R | 210 | plusminus hyphen macron | |
83 | s S | 211 | ||
84 | t T | 212 | copyright registered | |
85 | u U | 213 | guillemotleft guillemotright | |
86 | v V | 214 | masculine ordfeminine | |
87 | w W | 215 | ae AE | |
88 | x X | 216 | cent yen | |
89 | y Y | 217 | questiondown exclamdown | |
90 | z Z | 218 | onequarter onehalf threequarters | |
91 | 219 | |||
92 | 220 | less greater bar | ||
93 | 221 | plus asterisk asciitilde | ||
94 | 222 | |||
95 | 223 | |||
96 | KP_0 KP_0 | 224 | ||
97 | KP_1 KP_1 | 225 | ||
98 | KP_2 KP_2 | 226 | ||
99 | KP_3 KP_3 | 227 | multiply division | |
100 | KP_4 KP_4 | 228 | acircumflex Acircumflex | |
101 | KP_5 KP_5 | 229 | ecircumflex Ecircumflex | |
102 | KP_6 KP_6 | 230 | icircumflex Icircumflex | |
103 | KP_7 KP_7 | 231 | ocircumflex Ocircumflex | |
104 | KP_8 KP_8 | 232 | ucircumflex Ucircumflex | |
105 | KP_9 KP_9 | 233 | ntilde Ntilde | |
106 | KP_Multiply KP_Multiply | 234 | yacute Yacute | |
107 | KP_Add KP_Add | 235 | oslash Ooblique | |
108 | KP_Separator KP_Separator | 236 | aring Aring | |
109 | KP_Subtract KP_Subtract | 237 | ccedilla Ccedilla | |
110 | KP_Decimal KP_Decimal | 238 | thorn THORN | |
111 | KP_Divide KP_Divide | 239 | eth ETH | |
112 | F1 | 240 | diaeresis cedilla currency | |
113 | F2 | 241 | agrave Agrave atilde Atilde | |
114 | F3 | 242 | egrave Egrave | |
115 | F4 | 243 | igrave Igrave | |
116 | F5 | 244 | ograve Ograve otilde Otilde | |
117 | F6 | 245 | ugrave Ugrave | |
118 | F7 | 246 | adiaeresis Adiaeresis | |
119 | F8 | 247 | ediaeresis Ediaeresis | |
120 | F9 | 248 | idiaeresis Idiaeresis | |
121 | F10 | 249 | odiaeresis Odiaeresis | |
122 | F11 | 250 | udiaeresis Udiaeresis | |
123 | F12 | 251 | ssharp question backslash | |
124 | F13 | 252 | asciicircum degree | |
125 | F14 | 253 | 3 sterling | |
126 | F15 | 254 | Mode_switch | |
127 | F16 |
推荐阅读
-
【转】keyCode对照表及示例
-
php array 转json及java 转换 json数据格式操作示例
-
Python3实现的回文数判断及罗马数字转整数算法示例
-
json转String与String转json及判断对象类型示例代码
-
php array 转json及java 转换 json数据格式操作示例
-
Python3实现的回文数判断及罗马数字转整数算法示例
-
json转String与String转json及判断对象类型示例代码
-
json转js与js转json以及练习了ajax-xhr/fetch异步通讯以及模块常识,其中Promise状态及Promise中的Fetch API部分暂时还没进行示例学习操作
-
json转js与js转json以及练习了ajax-xhr/fetch异步通讯以及模块常识,其中Promise状态及Promise中的Fetch API部分暂时还没进行示例学习操作