任何人都可以为我提供键盘中用于Java中KeyEvent类的各个键的键码整数列表吗?
我想创建一个供用户选择的所有键盘键的下拉列表。我需要特定于键盘的列表。在这种情况下,VK常量没有帮助,因为我需要键盘上使用的键的“列表”。 This post here没有使用,因为它是针对Javascript的,并且与javadoc相比,所有密钥的代码都不相同。此外,javadoc中使用的KeyCode值都按字母顺序排列,因此很难在那里找到键盘键。我尝试使用Google搜索来源,但没有任何有趣的内容只出现在Javascript中。我应该自己一个一个地编译它们还是有更简单的方法?
编辑:我知道VK。我需要使用KeyEvent.getKeyText函数在下拉菜单中存储每个键盘键。所以我需要清单。这就是为什么我问我是否需要自己编译它们。我应该早点提到。每个密钥都是浪费时间。
答案 0 :(得分:16)
这是你的清单:
0 - Unknown keyCode: 0x0
1 - Unknown keyCode: 0x1
2 - Unknown keyCode: 0x2
3 - Cancel
4 - Unknown keyCode: 0x4
5 - Unknown keyCode: 0x5
6 - Unknown keyCode: 0x6
7 - Unknown keyCode: 0x7
8 - Backspace
9 - Tab
10 - Enter
11 - Unknown keyCode: 0xb
12 - Clear
13 - Unknown keyCode: 0xd
14 - Unknown keyCode: 0xe
15 - Unknown keyCode: 0xf
16 - Shift
17 - Ctrl
18 - Alt
19 - Pause
20 - Caps Lock
21 - Kana
22 - Unknown keyCode: 0x16
23 - Unknown keyCode: 0x17
24 - Final
25 - Kanji
26 - Unknown keyCode: 0x1a
27 - Escape
28 - Convert
29 - No Convert
30 - Accept
31 - Mode Change
32 - Space
33 - Page Up
34 - Page Down
35 - End
36 - Home
37 - Left
38 - Up
39 - Right
40 - Down
41 - Unknown keyCode: 0x29
42 - Unknown keyCode: 0x2a
43 - Unknown keyCode: 0x2b
44 - Comma
45 - Minus
46 - Period
47 - Slash
48 - 0
49 - 1
50 - 2
51 - 3
52 - 4
53 - 5
54 - 6
55 - 7
56 - 8
57 - 9
58 - Unknown keyCode: 0x3a
59 - Semicolon
60 - Unknown keyCode: 0x3c
61 - Equals
62 - Unknown keyCode: 0x3e
63 - Unknown keyCode: 0x3f
64 - Unknown keyCode: 0x40
65 - A
66 - B
67 - C
68 - D
69 - E
70 - F
71 - G
72 - H
73 - I
74 - J
75 - K
76 - L
77 - M
78 - N
79 - O
80 - P
81 - Q
82 - R
83 - S
84 - T
85 - U
86 - V
87 - W
88 - X
89 - Y
90 - Z
91 - Open Bracket
92 - Back Slash
93 - Close Bracket
94 - Unknown keyCode: 0x5e
95 - Unknown keyCode: 0x5f
96 - NumPad-0
97 - NumPad-1
98 - NumPad-2
99 - NumPad-3
100 - NumPad-4
101 - NumPad-5
102 - NumPad-6
103 - NumPad-7
104 - NumPad-8
105 - NumPad-9
106 - NumPad *
107 - NumPad +
108 - NumPad ,
109 - NumPad -
110 - NumPad .
111 - NumPad /
112 - F1
113 - F2
114 - F3
115 - F4
116 - F5
117 - F6
118 - F7
119 - F8
120 - F9
121 - F10
122 - F11
123 - F12
124 - Unknown keyCode: 0x7c
125 - Unknown keyCode: 0x7d
126 - Unknown keyCode: 0x7e
127 - Delete
128 - Dead Grave
129 - Dead Acute
130 - Dead Circumflex
131 - Dead Tilde
132 - Dead Macron
133 - Dead Breve
134 - Dead Above Dot
135 - Dead Diaeresis
136 - Dead Above Ring
137 - Dead Double Acute
138 - Dead Caron
139 - Dead Cedilla
140 - Dead Ogonek
141 - Dead Iota
142 - Dead Voiced Sound
143 - Dead Semivoiced Sound
144 - Num Lock
145 - Scroll Lock
146 - Unknown keyCode: 0x92
147 - Unknown keyCode: 0x93
148 - Unknown keyCode: 0x94
149 - Unknown keyCode: 0x95
150 - Ampersand
151 - Asterisk
152 - Double Quote
153 - Less
154 - Print Screen
155 - Insert
156 - Help
157 - Meta
158 - Unknown keyCode: 0x9e
159 - Unknown keyCode: 0x9f
160 - Greater
161 - Left Brace
162 - Right Brace
163 - Unknown keyCode: 0xa3
164 - Unknown keyCode: 0xa4
165 - Unknown keyCode: 0xa5
166 - Unknown keyCode: 0xa6
167 - Unknown keyCode: 0xa7
168 - Unknown keyCode: 0xa8
169 - Unknown keyCode: 0xa9
170 - Unknown keyCode: 0xaa
171 - Unknown keyCode: 0xab
172 - Unknown keyCode: 0xac
173 - Unknown keyCode: 0xad
174 - Unknown keyCode: 0xae
175 - Unknown keyCode: 0xaf
176 - Unknown keyCode: 0xb0
177 - Unknown keyCode: 0xb1
178 - Unknown keyCode: 0xb2
179 - Unknown keyCode: 0xb3
180 - Unknown keyCode: 0xb4
181 - Unknown keyCode: 0xb5
182 - Unknown keyCode: 0xb6
183 - Unknown keyCode: 0xb7
184 - Unknown keyCode: 0xb8
185 - Unknown keyCode: 0xb9
186 - Unknown keyCode: 0xba
187 - Unknown keyCode: 0xbb
188 - Unknown keyCode: 0xbc
189 - Unknown keyCode: 0xbd
190 - Unknown keyCode: 0xbe
191 - Unknown keyCode: 0xbf
192 - Back Quote
193 - Unknown keyCode: 0xc1
194 - Unknown keyCode: 0xc2
195 - Unknown keyCode: 0xc3
196 - Unknown keyCode: 0xc4
197 - Unknown keyCode: 0xc5
198 - Unknown keyCode: 0xc6
199 - Unknown keyCode: 0xc7
200 - Unknown keyCode: 0xc8
201 - Unknown keyCode: 0xc9
202 - Unknown keyCode: 0xca
203 - Unknown keyCode: 0xcb
204 - Unknown keyCode: 0xcc
205 - Unknown keyCode: 0xcd
206 - Unknown keyCode: 0xce
207 - Unknown keyCode: 0xcf
208 - Unknown keyCode: 0xd0
209 - Unknown keyCode: 0xd1
210 - Unknown keyCode: 0xd2
211 - Unknown keyCode: 0xd3
212 - Unknown keyCode: 0xd4
213 - Unknown keyCode: 0xd5
214 - Unknown keyCode: 0xd6
215 - Unknown keyCode: 0xd7
216 - Unknown keyCode: 0xd8
217 - Unknown keyCode: 0xd9
218 - Unknown keyCode: 0xda
219 - Unknown keyCode: 0xdb
220 - Unknown keyCode: 0xdc
221 - Unknown keyCode: 0xdd
222 - Quote
223 - Unknown keyCode: 0xdf
224 - Up
225 - Down
226 - Left
227 - Right
228 - Unknown keyCode: 0xe4
229 - Unknown keyCode: 0xe5
230 - Unknown keyCode: 0xe6
231 - Unknown keyCode: 0xe7
232 - Unknown keyCode: 0xe8
233 - Unknown keyCode: 0xe9
234 - Unknown keyCode: 0xea
235 - Unknown keyCode: 0xeb
236 - Unknown keyCode: 0xec
237 - Unknown keyCode: 0xed
238 - Unknown keyCode: 0xee
239 - Unknown keyCode: 0xef
240 - Alphanumeric
241 - Katakana
242 - Hiragana
243 - Full-Width
244 - Half-Width
245 - Roman Characters
246 - Unknown keyCode: 0xf6
247 - Unknown keyCode: 0xf7
248 - Unknown keyCode: 0xf8
249 - Unknown keyCode: 0xf9
250 - Unknown keyCode: 0xfa
251 - Unknown keyCode: 0xfb
252 - Unknown keyCode: 0xfc
253 - Unknown keyCode: 0xfd
254 - Unknown keyCode: 0xfe
255 - Unknown keyCode: 0xff
256 - All Candidates
257 - Previous Candidate
258 - Code Input
259 - Japanese Katakana
260 - Japanese Hiragana
261 - Japanese Roman
262 - Kana Lock
263 - Input Method On/Off
264 - Unknown keyCode: 0x108
265 - Unknown keyCode: 0x109
266 - Unknown keyCode: 0x10a
267 - Unknown keyCode: 0x10b
268 - Unknown keyCode: 0x10c
269 - Unknown keyCode: 0x10d
270 - Unknown keyCode: 0x10e
271 - Unknown keyCode: 0x10f
272 - Unknown keyCode: 0x110
273 - Unknown keyCode: 0x111
274 - Unknown keyCode: 0x112
275 - Unknown keyCode: 0x113
276 - Unknown keyCode: 0x114
277 - Unknown keyCode: 0x115
278 - Unknown keyCode: 0x116
279 - Unknown keyCode: 0x117
280 - Unknown keyCode: 0x118
281 - Unknown keyCode: 0x119
282 - Unknown keyCode: 0x11a
283 - Unknown keyCode: 0x11b
284 - Unknown keyCode: 0x11c
285 - Unknown keyCode: 0x11d
286 - Unknown keyCode: 0x11e
287 - Unknown keyCode: 0x11f
288 - Unknown keyCode: 0x120
289 - Unknown keyCode: 0x121
290 - Unknown keyCode: 0x122
291 - Unknown keyCode: 0x123
292 - Unknown keyCode: 0x124
293 - Unknown keyCode: 0x125
294 - Unknown keyCode: 0x126
295 - Unknown keyCode: 0x127
296 - Unknown keyCode: 0x128
297 - Unknown keyCode: 0x129
298 - Unknown keyCode: 0x12a
299 - Unknown keyCode: 0x12b
300 - Unknown keyCode: 0x12c
301 - Unknown keyCode: 0x12d
302 - Unknown keyCode: 0x12e
303 - Unknown keyCode: 0x12f
304 - Unknown keyCode: 0x130
305 - Unknown keyCode: 0x131
306 - Unknown keyCode: 0x132
307 - Unknown keyCode: 0x133
308 - Unknown keyCode: 0x134
309 - Unknown keyCode: 0x135
310 - Unknown keyCode: 0x136
311 - Unknown keyCode: 0x137
312 - Unknown keyCode: 0x138
313 - Unknown keyCode: 0x139
314 - Unknown keyCode: 0x13a
315 - Unknown keyCode: 0x13b
316 - Unknown keyCode: 0x13c
317 - Unknown keyCode: 0x13d
318 - Unknown keyCode: 0x13e
319 - Unknown keyCode: 0x13f
320 - Unknown keyCode: 0x140
321 - Unknown keyCode: 0x141
322 - Unknown keyCode: 0x142
323 - Unknown keyCode: 0x143
324 - Unknown keyCode: 0x144
325 - Unknown keyCode: 0x145
326 - Unknown keyCode: 0x146
327 - Unknown keyCode: 0x147
328 - Unknown keyCode: 0x148
329 - Unknown keyCode: 0x149
330 - Unknown keyCode: 0x14a
331 - Unknown keyCode: 0x14b
332 - Unknown keyCode: 0x14c
333 - Unknown keyCode: 0x14d
334 - Unknown keyCode: 0x14e
335 - Unknown keyCode: 0x14f
336 - Unknown keyCode: 0x150
337 - Unknown keyCode: 0x151
338 - Unknown keyCode: 0x152
339 - Unknown keyCode: 0x153
340 - Unknown keyCode: 0x154
341 - Unknown keyCode: 0x155
342 - Unknown keyCode: 0x156
343 - Unknown keyCode: 0x157
344 - Unknown keyCode: 0x158
345 - Unknown keyCode: 0x159
346 - Unknown keyCode: 0x15a
347 - Unknown keyCode: 0x15b
348 - Unknown keyCode: 0x15c
349 - Unknown keyCode: 0x15d
350 - Unknown keyCode: 0x15e
351 - Unknown keyCode: 0x15f
352 - Unknown keyCode: 0x160
353 - Unknown keyCode: 0x161
354 - Unknown keyCode: 0x162
355 - Unknown keyCode: 0x163
356 - Unknown keyCode: 0x164
357 - Unknown keyCode: 0x165
358 - Unknown keyCode: 0x166
359 - Unknown keyCode: 0x167
360 - Unknown keyCode: 0x168
361 - Unknown keyCode: 0x169
362 - Unknown keyCode: 0x16a
363 - Unknown keyCode: 0x16b
364 - Unknown keyCode: 0x16c
365 - Unknown keyCode: 0x16d
366 - Unknown keyCode: 0x16e
367 - Unknown keyCode: 0x16f
368 - Unknown keyCode: 0x170
369 - Unknown keyCode: 0x171
370 - Unknown keyCode: 0x172
371 - Unknown keyCode: 0x173
372 - Unknown keyCode: 0x174
373 - Unknown keyCode: 0x175
374 - Unknown keyCode: 0x176
375 - Unknown keyCode: 0x177
376 - Unknown keyCode: 0x178
377 - Unknown keyCode: 0x179
378 - Unknown keyCode: 0x17a
379 - Unknown keyCode: 0x17b
380 - Unknown keyCode: 0x17c
381 - Unknown keyCode: 0x17d
382 - Unknown keyCode: 0x17e
383 - Unknown keyCode: 0x17f
384 - Unknown keyCode: 0x180
385 - Unknown keyCode: 0x181
386 - Unknown keyCode: 0x182
387 - Unknown keyCode: 0x183
388 - Unknown keyCode: 0x184
389 - Unknown keyCode: 0x185
390 - Unknown keyCode: 0x186
391 - Unknown keyCode: 0x187
392 - Unknown keyCode: 0x188
393 - Unknown keyCode: 0x189
394 - Unknown keyCode: 0x18a
395 - Unknown keyCode: 0x18b
396 - Unknown keyCode: 0x18c
397 - Unknown keyCode: 0x18d
398 - Unknown keyCode: 0x18e
399 - Unknown keyCode: 0x18f
400 - Unknown keyCode: 0x190
401 - Unknown keyCode: 0x191
402 - Unknown keyCode: 0x192
403 - Unknown keyCode: 0x193
404 - Unknown keyCode: 0x194
405 - Unknown keyCode: 0x195
406 - Unknown keyCode: 0x196
407 - Unknown keyCode: 0x197
408 - Unknown keyCode: 0x198
409 - Unknown keyCode: 0x199
410 - Unknown keyCode: 0x19a
411 - Unknown keyCode: 0x19b
412 - Unknown keyCode: 0x19c
413 - Unknown keyCode: 0x19d
414 - Unknown keyCode: 0x19e
415 - Unknown keyCode: 0x19f
416 - Unknown keyCode: 0x1a0
417 - Unknown keyCode: 0x1a1
418 - Unknown keyCode: 0x1a2
419 - Unknown keyCode: 0x1a3
420 - Unknown keyCode: 0x1a4
421 - Unknown keyCode: 0x1a5
422 - Unknown keyCode: 0x1a6
423 - Unknown keyCode: 0x1a7
424 - Unknown keyCode: 0x1a8
425 - Unknown keyCode: 0x1a9
426 - Unknown keyCode: 0x1aa
427 - Unknown keyCode: 0x1ab
428 - Unknown keyCode: 0x1ac
429 - Unknown keyCode: 0x1ad
430 - Unknown keyCode: 0x1ae
431 - Unknown keyCode: 0x1af
432 - Unknown keyCode: 0x1b0
433 - Unknown keyCode: 0x1b1
434 - Unknown keyCode: 0x1b2
435 - Unknown keyCode: 0x1b3
436 - Unknown keyCode: 0x1b4
437 - Unknown keyCode: 0x1b5
438 - Unknown keyCode: 0x1b6
439 - Unknown keyCode: 0x1b7
440 - Unknown keyCode: 0x1b8
441 - Unknown keyCode: 0x1b9
442 - Unknown keyCode: 0x1ba
443 - Unknown keyCode: 0x1bb
444 - Unknown keyCode: 0x1bc
445 - Unknown keyCode: 0x1bd
446 - Unknown keyCode: 0x1be
447 - Unknown keyCode: 0x1bf
448 - Unknown keyCode: 0x1c0
449 - Unknown keyCode: 0x1c1
450 - Unknown keyCode: 0x1c2
451 - Unknown keyCode: 0x1c3
452 - Unknown keyCode: 0x1c4
453 - Unknown keyCode: 0x1c5
454 - Unknown keyCode: 0x1c6
455 - Unknown keyCode: 0x1c7
456 - Unknown keyCode: 0x1c8
457 - Unknown keyCode: 0x1c9
458 - Unknown keyCode: 0x1ca
459 - Unknown keyCode: 0x1cb
460 - Unknown keyCode: 0x1cc
461 - Unknown keyCode: 0x1cd
462 - Unknown keyCode: 0x1ce
463 - Unknown keyCode: 0x1cf
464 - Unknown keyCode: 0x1d0
465 - Unknown keyCode: 0x1d1
466 - Unknown keyCode: 0x1d2
467 - Unknown keyCode: 0x1d3
468 - Unknown keyCode: 0x1d4
469 - Unknown keyCode: 0x1d5
470 - Unknown keyCode: 0x1d6
471 - Unknown keyCode: 0x1d7
472 - Unknown keyCode: 0x1d8
473 - Unknown keyCode: 0x1d9
474 - Unknown keyCode: 0x1da
475 - Unknown keyCode: 0x1db
476 - Unknown keyCode: 0x1dc
477 - Unknown keyCode: 0x1dd
478 - Unknown keyCode: 0x1de
479 - Unknown keyCode: 0x1df
480 - Unknown keyCode: 0x1e0
481 - Unknown keyCode: 0x1e1
482 - Unknown keyCode: 0x1e2
483 - Unknown keyCode: 0x1e3
484 - Unknown keyCode: 0x1e4
485 - Unknown keyCode: 0x1e5
486 - Unknown keyCode: 0x1e6
487 - Unknown keyCode: 0x1e7
488 - Unknown keyCode: 0x1e8
489 - Unknown keyCode: 0x1e9
490 - Unknown keyCode: 0x1ea
491 - Unknown keyCode: 0x1eb
492 - Unknown keyCode: 0x1ec
493 - Unknown keyCode: 0x1ed
494 - Unknown keyCode: 0x1ee
495 - Unknown keyCode: 0x1ef
496 - Unknown keyCode: 0x1f0
497 - Unknown keyCode: 0x1f1
498 - Unknown keyCode: 0x1f2
499 - Unknown keyCode: 0x1f3
500 - Unknown keyCode: 0x1f4
501 - Unknown keyCode: 0x1f5
502 - Unknown keyCode: 0x1f6
503 - Unknown keyCode: 0x1f7
504 - Unknown keyCode: 0x1f8
505 - Unknown keyCode: 0x1f9
506 - Unknown keyCode: 0x1fa
507 - Unknown keyCode: 0x1fb
508 - Unknown keyCode: 0x1fc
509 - Unknown keyCode: 0x1fd
510 - Unknown keyCode: 0x1fe
511 - Unknown keyCode: 0x1ff
512 - At
513 - Colon
514 - Circumflex
515 - Dollar
516 - Euro
517 - Exclamation Mark
518 - Inverted Exclamation Mark
519 - Left Parenthesis
520 - Number Sign
521 - Plus
522 - Right Parenthesis
523 - Underscore
524 - Windows
525 - Context Menu
答案 1 :(得分:10)
KeyEvent类包含具有这些值的静态字段。
例如,KeyEvent.VK_A
代表“A”键。
要获取字段名称,可以使用反射:
Field[] fields = java.awt.event.KeyEvent.class.getDeclaredFields();
for (Field f : fields) {
if (Modifier.isStatic(f.getModifiers())) {
System.out.println(f.getName());
}
}
答案 2 :(得分:4)
您无需知道密钥代码的确切值。 KeyEvent
类具有定义所有键代码的常量字段:
KeyEvent.VK_A
KeyEvent.VK_ENTER
KeyEvent.VK_SPACE
等
请仔细阅读Javadoc。所有常数值也可以在这里找到:
http://docs.oracle.com/javase/7/docs/api/constant-values.html
答案 3 :(得分:1)
您可以尝试使用该程序获取KeyEvent
类中字段的所有int值
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyEvent;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
public class RobotClass
{
public static void main(String[] args)
{
ArrayList<Integer> values = new ArrayList<>();
try{
Robot robot = new Robot();
Field[] fields = java.awt.event.KeyEvent.class.getDeclaredFields();
for (Field f : fields) {
if (Modifier.isStatic(f.getModifiers())) {
values.add(f.getInt(f.getName()));
}
}
}
catch(Exception e){
Collections.sort(values);
for(int i:values) System.out.println(i);
}
}
}
答案 4 :(得分:-1)
在此处查找“ java.awt.event.KeyEvent”部分;