1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.keyboardmaps; |
---|
16 | |
---|
17 | import java.awt.event.KeyEvent; |
---|
18 | |
---|
19 | /** |
---|
20 | * <p> |
---|
21 | * Enumeration of virtual keys. |
---|
22 | * </p> |
---|
23 | * |
---|
24 | * @version 1.0 |
---|
25 | * @author Patrick Harms |
---|
26 | */ |
---|
27 | public enum VirtualKey { |
---|
28 | |
---|
29 | ENTER(KeyEvent.VK_ENTER), |
---|
30 | BACK_SPACE(KeyEvent.VK_BACK_SPACE), |
---|
31 | TAB(KeyEvent.VK_TAB), |
---|
32 | CANCEL(KeyEvent.VK_CANCEL), |
---|
33 | CLEAR(KeyEvent.VK_CLEAR), |
---|
34 | SHIFT(KeyEvent.VK_SHIFT), |
---|
35 | CONTROL(KeyEvent.VK_CONTROL), |
---|
36 | ALT(KeyEvent.VK_ALT), |
---|
37 | PAUSE(KeyEvent.VK_PAUSE), |
---|
38 | CAPS_LOCK(KeyEvent.VK_CAPS_LOCK), |
---|
39 | ESCAPE(KeyEvent.VK_ESCAPE), |
---|
40 | SPACE(KeyEvent.VK_SPACE), |
---|
41 | PAGE_UP(KeyEvent.VK_PAGE_UP), |
---|
42 | PAGE_DOWN(KeyEvent.VK_PAGE_DOWN), |
---|
43 | END(KeyEvent.VK_END), |
---|
44 | HOME(KeyEvent.VK_HOME), |
---|
45 | |
---|
46 | LEFT(KeyEvent.VK_LEFT), |
---|
47 | UP(KeyEvent.VK_UP), |
---|
48 | RIGHT(KeyEvent.VK_RIGHT), |
---|
49 | DOWN(KeyEvent.VK_DOWN), |
---|
50 | |
---|
51 | COMMA(KeyEvent.VK_COMMA), |
---|
52 | MINUS(KeyEvent.VK_MINUS), |
---|
53 | PERIOD(KeyEvent.VK_PERIOD), |
---|
54 | SLASH(KeyEvent.VK_SLASH), |
---|
55 | |
---|
56 | DIGIT_0(KeyEvent.VK_0), |
---|
57 | DIGIT_1(KeyEvent.VK_1), |
---|
58 | DIGIT_2(KeyEvent.VK_2), |
---|
59 | DIGIT_3(KeyEvent.VK_3), |
---|
60 | DIGIT_4(KeyEvent.VK_4), |
---|
61 | DIGIT_5(KeyEvent.VK_5), |
---|
62 | DIGIT_6(KeyEvent.VK_6), |
---|
63 | DIGIT_7(KeyEvent.VK_7), |
---|
64 | DIGIT_8(KeyEvent.VK_8), |
---|
65 | DIGIT_9(KeyEvent.VK_9), |
---|
66 | |
---|
67 | SEMICOLON(KeyEvent.VK_SEMICOLON), |
---|
68 | EQUALS(KeyEvent.VK_EQUALS), |
---|
69 | |
---|
70 | LETTER_A(KeyEvent.VK_A), |
---|
71 | LETTER_B(KeyEvent.VK_B), |
---|
72 | LETTER_C(KeyEvent.VK_C), |
---|
73 | LETTER_D(KeyEvent.VK_D), |
---|
74 | LETTER_E(KeyEvent.VK_E), |
---|
75 | LETTER_F(KeyEvent.VK_F), |
---|
76 | LETTER_G(KeyEvent.VK_G), |
---|
77 | LETTER_H(KeyEvent.VK_H), |
---|
78 | LETTER_I(KeyEvent.VK_I), |
---|
79 | LETTER_J(KeyEvent.VK_J), |
---|
80 | LETTER_K(KeyEvent.VK_K), |
---|
81 | LETTER_L(KeyEvent.VK_L), |
---|
82 | LETTER_M(KeyEvent.VK_M), |
---|
83 | LETTER_N(KeyEvent.VK_N), |
---|
84 | LETTER_O(KeyEvent.VK_O), |
---|
85 | LETTER_P(KeyEvent.VK_P), |
---|
86 | LETTER_Q(KeyEvent.VK_Q), |
---|
87 | LETTER_R(KeyEvent.VK_R), |
---|
88 | LETTER_S(KeyEvent.VK_S), |
---|
89 | LETTER_T(KeyEvent.VK_T), |
---|
90 | LETTER_U(KeyEvent.VK_U), |
---|
91 | LETTER_V(KeyEvent.VK_V), |
---|
92 | LETTER_W(KeyEvent.VK_W), |
---|
93 | LETTER_X(KeyEvent.VK_X), |
---|
94 | LETTER_Y(KeyEvent.VK_Y), |
---|
95 | LETTER_Z(KeyEvent.VK_Z), |
---|
96 | |
---|
97 | OPEN_BRACKET(KeyEvent.VK_OPEN_BRACKET), |
---|
98 | BACK_SLASH(KeyEvent.VK_BACK_SLASH), |
---|
99 | CLOSE_BRACKET(KeyEvent.VK_CLOSE_BRACKET), |
---|
100 | |
---|
101 | NUMPAD_0(KeyEvent.VK_NUMPAD0), |
---|
102 | NUMPAD_1(KeyEvent.VK_NUMPAD1), |
---|
103 | NUMPAD_2(KeyEvent.VK_NUMPAD2), |
---|
104 | NUMPAD_3(KeyEvent.VK_NUMPAD3), |
---|
105 | NUMPAD_4(KeyEvent.VK_NUMPAD4), |
---|
106 | NUMPAD_5(KeyEvent.VK_NUMPAD5), |
---|
107 | NUMPAD_6(KeyEvent.VK_NUMPAD6), |
---|
108 | NUMPAD_7(KeyEvent.VK_NUMPAD7), |
---|
109 | NUMPAD_8(KeyEvent.VK_NUMPAD8), |
---|
110 | NUMPAD_9(KeyEvent.VK_NUMPAD9), |
---|
111 | MULTIPLY(KeyEvent.VK_MULTIPLY), |
---|
112 | ADD(KeyEvent.VK_ADD), |
---|
113 | |
---|
114 | SEPARATOR(KeyEvent.VK_SEPARATOR), |
---|
115 | |
---|
116 | SUBTRACT(KeyEvent.VK_SUBTRACT), |
---|
117 | DECIMAL(KeyEvent.VK_DECIMAL), |
---|
118 | DIVIDE(KeyEvent.VK_DIVIDE), |
---|
119 | DELETE(KeyEvent.VK_DELETE), |
---|
120 | NUM_LOCK(KeyEvent.VK_NUM_LOCK), |
---|
121 | SCROLL_LOCK(KeyEvent.VK_SCROLL_LOCK), |
---|
122 | |
---|
123 | F1(KeyEvent.VK_F1), |
---|
124 | F2(KeyEvent.VK_F2), |
---|
125 | F3(KeyEvent.VK_F3), |
---|
126 | F4(KeyEvent.VK_F4), |
---|
127 | F5(KeyEvent.VK_F5), |
---|
128 | F6(KeyEvent.VK_F6), |
---|
129 | F7(KeyEvent.VK_F7), |
---|
130 | F8(KeyEvent.VK_F8), |
---|
131 | F9(KeyEvent.VK_F9), |
---|
132 | F10(KeyEvent.VK_F10), |
---|
133 | F11(KeyEvent.VK_F11), |
---|
134 | F12(KeyEvent.VK_F12), |
---|
135 | F13(KeyEvent.VK_F13), |
---|
136 | F14(KeyEvent.VK_F14), |
---|
137 | F15(KeyEvent.VK_F15), |
---|
138 | F16(KeyEvent.VK_F16), |
---|
139 | F17(KeyEvent.VK_F17), |
---|
140 | F18(KeyEvent.VK_F18), |
---|
141 | F19(KeyEvent.VK_F19), |
---|
142 | F20(KeyEvent.VK_F20), |
---|
143 | F21(KeyEvent.VK_F21), |
---|
144 | F22(KeyEvent.VK_F22), |
---|
145 | F23(KeyEvent.VK_F23), |
---|
146 | F24(KeyEvent.VK_F24), |
---|
147 | |
---|
148 | PRINTSCREEN(KeyEvent.VK_PRINTSCREEN), |
---|
149 | INSERT(KeyEvent.VK_INSERT), |
---|
150 | HELP(KeyEvent.VK_HELP), |
---|
151 | META(KeyEvent.VK_META), |
---|
152 | |
---|
153 | BACK_QUOTE(KeyEvent.VK_BACK_QUOTE), |
---|
154 | QUOTE(KeyEvent.VK_QUOTE), |
---|
155 | |
---|
156 | KP_UP(KeyEvent.VK_KP_UP), |
---|
157 | KP_DOWN(KeyEvent.VK_KP_DOWN), |
---|
158 | KP_LEFT(KeyEvent.VK_KP_LEFT), |
---|
159 | KP_RIGHT(KeyEvent.VK_KP_RIGHT), |
---|
160 | |
---|
161 | DEAD_GRAVE(KeyEvent.VK_DEAD_GRAVE), |
---|
162 | DEAD_ACUTE(KeyEvent.VK_DEAD_ACUTE), |
---|
163 | DEAD_CIRCUMFLEX(KeyEvent.VK_DEAD_CIRCUMFLEX), |
---|
164 | DEAD_TILDE(KeyEvent.VK_DEAD_TILDE), |
---|
165 | DEAD_MACRON(KeyEvent.VK_DEAD_MACRON), |
---|
166 | DEAD_BREVE(KeyEvent.VK_DEAD_BREVE), |
---|
167 | DEAD_ABOVEDOT(KeyEvent.VK_DEAD_ABOVEDOT), |
---|
168 | DEAD_DIAERESIS(KeyEvent.VK_DEAD_DIAERESIS), |
---|
169 | DEAD_ABOVERING(KeyEvent.VK_DEAD_ABOVERING), |
---|
170 | DEAD_DOUBLEACUTE(KeyEvent.VK_DEAD_DOUBLEACUTE), |
---|
171 | DEAD_CARON(KeyEvent.VK_DEAD_CARON), |
---|
172 | DEAD_CEDILLA(KeyEvent.VK_DEAD_CEDILLA), |
---|
173 | DEAD_OGONEK(KeyEvent.VK_DEAD_OGONEK), |
---|
174 | DEAD_IOTA(KeyEvent.VK_DEAD_IOTA), |
---|
175 | DEAD_VOICED_SOUND(KeyEvent.VK_DEAD_VOICED_SOUND), |
---|
176 | DEAD_SEMIVOICED_SOUND(KeyEvent.VK_DEAD_SEMIVOICED_SOUND), |
---|
177 | |
---|
178 | AMPERSAND(KeyEvent.VK_AMPERSAND), |
---|
179 | ASTERISK(KeyEvent.VK_ASTERISK), |
---|
180 | QUOTEDBL(KeyEvent.VK_QUOTEDBL), |
---|
181 | LESS(KeyEvent.VK_LESS), |
---|
182 | GREATER(KeyEvent.VK_GREATER), |
---|
183 | BRACELEFT(KeyEvent.VK_BRACELEFT), |
---|
184 | BRACERIGHT(KeyEvent.VK_BRACERIGHT), |
---|
185 | |
---|
186 | AT(KeyEvent.VK_AT), |
---|
187 | COLON(KeyEvent.VK_COLON), |
---|
188 | CIRCUMFLEX(KeyEvent.VK_CIRCUMFLEX), |
---|
189 | DOLLAR(KeyEvent.VK_DOLLAR), |
---|
190 | EURO_SIGN(KeyEvent.VK_EURO_SIGN), |
---|
191 | EXCLAMATION_MARK(KeyEvent.VK_EXCLAMATION_MARK), |
---|
192 | INVERTED_EXCLAMATION_MARK(KeyEvent.VK_INVERTED_EXCLAMATION_MARK), |
---|
193 | LEFT_PARENTHESIS(KeyEvent.VK_LEFT_PARENTHESIS), |
---|
194 | NUMBER_SIGN(KeyEvent.VK_NUMBER_SIGN), |
---|
195 | PLUS(KeyEvent.VK_PLUS), |
---|
196 | RIGHT_PARENTHESIS(KeyEvent.VK_RIGHT_PARENTHESIS), |
---|
197 | UNDERSCORE(KeyEvent.VK_UNDERSCORE), |
---|
198 | |
---|
199 | WINDOWS(KeyEvent.VK_WINDOWS), |
---|
200 | CONTEXT_MENU(KeyEvent.VK_CONTEXT_MENU), |
---|
201 | |
---|
202 | FINAL(KeyEvent.VK_FINAL), |
---|
203 | CONVERT(KeyEvent.VK_CONVERT), |
---|
204 | NONCONVERT(KeyEvent.VK_NONCONVERT), |
---|
205 | ACCEPT(KeyEvent.VK_ACCEPT), |
---|
206 | MODECHANGE(KeyEvent.VK_MODECHANGE), |
---|
207 | KANA(KeyEvent.VK_KANA), |
---|
208 | KANJI(KeyEvent.VK_KANJI), |
---|
209 | ALPHANUMERIC(KeyEvent.VK_ALPHANUMERIC), |
---|
210 | KATAKANA(KeyEvent.VK_KATAKANA), |
---|
211 | HIRAGANA(KeyEvent.VK_HIRAGANA), |
---|
212 | FULL_WIDTH(KeyEvent.VK_FULL_WIDTH), |
---|
213 | HALF_WIDTH(KeyEvent.VK_HALF_WIDTH), |
---|
214 | ROMAN_CHARACTERS(KeyEvent.VK_ROMAN_CHARACTERS), |
---|
215 | ALL_CANDIDATES(KeyEvent.VK_ALL_CANDIDATES), |
---|
216 | PREVIOUS_CANDIDATE(KeyEvent.VK_PREVIOUS_CANDIDATE), |
---|
217 | CODE_INPUT(KeyEvent.VK_CODE_INPUT), |
---|
218 | JAPANESE_KATAKANA(KeyEvent.VK_JAPANESE_KATAKANA), |
---|
219 | JAPANESE_HIRAGANA(KeyEvent.VK_JAPANESE_HIRAGANA), |
---|
220 | JAPANESE_ROMAN(KeyEvent.VK_JAPANESE_ROMAN), |
---|
221 | KANA_LOCK(KeyEvent.VK_KANA_LOCK), |
---|
222 | INPUT_METHOD_ON_OFF(KeyEvent.VK_INPUT_METHOD_ON_OFF), |
---|
223 | |
---|
224 | CUT(KeyEvent.VK_CUT), |
---|
225 | COPY(KeyEvent.VK_COPY), |
---|
226 | PASTE(KeyEvent.VK_PASTE), |
---|
227 | UNDO(KeyEvent.VK_UNDO), |
---|
228 | AGAIN(KeyEvent.VK_AGAIN), |
---|
229 | FIND(KeyEvent.VK_FIND), |
---|
230 | PROPS(KeyEvent.VK_PROPS), |
---|
231 | STOP(KeyEvent.VK_STOP), |
---|
232 | COMPOSE(KeyEvent.VK_COMPOSE), |
---|
233 | ALT_GRAPH(KeyEvent.VK_ALT_GRAPH), |
---|
234 | BEGIN(KeyEvent.VK_BEGIN), |
---|
235 | |
---|
236 | UNDEFINED(KeyEvent.VK_UNDEFINED); |
---|
237 | |
---|
238 | /* |
---|
239 | * BAR(KeyEvent.VK_UNDEFINED), |
---|
240 | * APOSTROPHE(KeyEvent.VK_UNDEFINED), |
---|
241 | * QUESTIONMARK(KeyEvent.VK_UNDEFINED), |
---|
242 | * DEGREE(KeyEvent.VK_UNDEFINED), |
---|
243 | * HENKAN_MODE(KeyEvent.VK_UNDEFINED), |
---|
244 | * MUHENKAN(KeyEvent.VK_UNDEFINED), |
---|
245 | * EISU_TOGGLE(KeyEvent.VK_UNDEFINED), |
---|
246 | * HANGUL(KeyEvent.VK_UNDEFINED), |
---|
247 | * HANGUL_HANJA(KeyEvent.VK_UNDEFINED), |
---|
248 | * EXECUTE(KeyEvent.VK_UNDEFINED); |
---|
249 | */ |
---|
250 | |
---|
251 | /** |
---|
252 | * <p> |
---|
253 | * Virtual key code of the virtual key. |
---|
254 | * </p> |
---|
255 | */ |
---|
256 | private int virtualKeyCode = -1; |
---|
257 | |
---|
258 | /** |
---|
259 | * <p> |
---|
260 | * Description of the virtual key. |
---|
261 | * </p> |
---|
262 | */ |
---|
263 | private String description; |
---|
264 | |
---|
265 | /** |
---|
266 | * <p> |
---|
267 | * Constructor. Creates a new VirtualKey. |
---|
268 | * </p> |
---|
269 | * |
---|
270 | * @param virtualKeyCode |
---|
271 | * key code of the virtual key |
---|
272 | */ |
---|
273 | private VirtualKey(int virtualKeyCode) { |
---|
274 | this.virtualKeyCode = virtualKeyCode; |
---|
275 | this.description = KeyEvent.getKeyText(this.virtualKeyCode); |
---|
276 | } |
---|
277 | |
---|
278 | /** |
---|
279 | * <p> |
---|
280 | * Returns the description of the virtual key. |
---|
281 | * </p> |
---|
282 | * |
---|
283 | * @return the description. |
---|
284 | */ |
---|
285 | String getDescription() { |
---|
286 | return description; |
---|
287 | } |
---|
288 | |
---|
289 | /** |
---|
290 | * <p> |
---|
291 | * Returns the keyCode of the virtual key. |
---|
292 | * </p> |
---|
293 | * |
---|
294 | * @return the keyCode. |
---|
295 | */ |
---|
296 | public int getVirtualKeyCode() { |
---|
297 | return virtualKeyCode; |
---|
298 | } |
---|
299 | |
---|
300 | /** |
---|
301 | * <p> |
---|
302 | * Returns whether the key is a combination key (e.g., shift, alt) or not. |
---|
303 | * </p> |
---|
304 | * |
---|
305 | * @return true, if the key is a combiniation key; false otherwise |
---|
306 | */ |
---|
307 | public boolean isCombinationKey() { |
---|
308 | switch (this) |
---|
309 | { |
---|
310 | case SHIFT: |
---|
311 | case CONTROL: |
---|
312 | case ALT: |
---|
313 | case ALT_GRAPH: |
---|
314 | case WINDOWS: |
---|
315 | return true; |
---|
316 | |
---|
317 | default: |
---|
318 | return false; |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | /** |
---|
323 | * <p> |
---|
324 | * Returns whether the key is a lock key (e.g., caps lock, num lock) or not. |
---|
325 | * </p> |
---|
326 | * |
---|
327 | * @return true, if the key is a lock key; false otherwise |
---|
328 | */ |
---|
329 | public boolean isLockKey() { |
---|
330 | switch (this) |
---|
331 | { |
---|
332 | case CAPS_LOCK: |
---|
333 | case NUM_LOCK: |
---|
334 | case SCROLL_LOCK: |
---|
335 | return true; |
---|
336 | |
---|
337 | default: |
---|
338 | return false; |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | /** |
---|
343 | * <p> |
---|
344 | * Returns whether the key is shift. |
---|
345 | * </p> |
---|
346 | * |
---|
347 | * @return true, if the key is shift; false otherwise |
---|
348 | */ |
---|
349 | public boolean isShiftKey() { |
---|
350 | switch (this) |
---|
351 | { |
---|
352 | case SHIFT: |
---|
353 | return true; |
---|
354 | |
---|
355 | default: |
---|
356 | return false; |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * <p> |
---|
362 | * Returns whether the is an alt key. |
---|
363 | * </p> |
---|
364 | * |
---|
365 | * @return true, if the key is alt or altgr; false otherwise |
---|
366 | */ |
---|
367 | public boolean isAltKey() { |
---|
368 | switch (this) |
---|
369 | { |
---|
370 | case ALT: |
---|
371 | case ALT_GRAPH: |
---|
372 | return true; |
---|
373 | |
---|
374 | default: |
---|
375 | return false; |
---|
376 | } |
---|
377 | } |
---|
378 | |
---|
379 | /** |
---|
380 | * <p> |
---|
381 | * Returns whether the key is control. |
---|
382 | * </p> |
---|
383 | * |
---|
384 | * @return true, if the key is control; false otherwise |
---|
385 | */ |
---|
386 | public boolean isControlKey() { |
---|
387 | switch (this) |
---|
388 | { |
---|
389 | case CONTROL: |
---|
390 | return true; |
---|
391 | |
---|
392 | default: |
---|
393 | return false; |
---|
394 | } |
---|
395 | } |
---|
396 | |
---|
397 | /** |
---|
398 | * <p> |
---|
399 | * Returns whether the key is the windows key. |
---|
400 | * </p> |
---|
401 | * |
---|
402 | * @return true, if the key is the windows key; false otherwise |
---|
403 | */ |
---|
404 | public boolean isWindowsKey() { |
---|
405 | switch (this) |
---|
406 | { |
---|
407 | case WINDOWS: |
---|
408 | return true; |
---|
409 | |
---|
410 | default: |
---|
411 | return false; |
---|
412 | } |
---|
413 | } |
---|
414 | |
---|
415 | /** |
---|
416 | * <p> |
---|
417 | * Returns whether the key is the meta key. |
---|
418 | * </p> |
---|
419 | * |
---|
420 | * @return true, if the key is the meta key; false otherwise |
---|
421 | */ |
---|
422 | public boolean isMetaKey() { |
---|
423 | switch (this) |
---|
424 | { |
---|
425 | case META: |
---|
426 | return true; |
---|
427 | |
---|
428 | default: |
---|
429 | return false; |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | /** |
---|
434 | * <p> |
---|
435 | * Returns whether the key is a letter. |
---|
436 | * </p> |
---|
437 | * |
---|
438 | * @return true, if the key is a letter; false otherwise |
---|
439 | */ |
---|
440 | public boolean isLetter() { |
---|
441 | if (virtualKeyCode > -1) { |
---|
442 | return Character.isLetter((char) virtualKeyCode); |
---|
443 | } |
---|
444 | else { |
---|
445 | return false; |
---|
446 | } |
---|
447 | } |
---|
448 | |
---|
449 | /** |
---|
450 | * <p> |
---|
451 | * Returns whether the key is a digit. |
---|
452 | * </p> |
---|
453 | * |
---|
454 | * @return true, if the key is a digit; false otherwise |
---|
455 | */ |
---|
456 | public boolean isDigit() { |
---|
457 | if (virtualKeyCode > -1) { |
---|
458 | return Character.isDigit(virtualKeyCode); |
---|
459 | } |
---|
460 | else { |
---|
461 | return false; |
---|
462 | } |
---|
463 | } |
---|
464 | |
---|
465 | /** |
---|
466 | * <p> |
---|
467 | * Parses an {@link String} and returns the respective VirtualKey if possible. |
---|
468 | * </p> |
---|
469 | * |
---|
470 | * @param string |
---|
471 | * String representation of the virtual key |
---|
472 | * @return created VirtualKey |
---|
473 | * @throws IllegalArgumentException |
---|
474 | * thrown if there is no VirtualKey that correlates to string |
---|
475 | */ |
---|
476 | public static VirtualKey parseVirtualKey(String string) { |
---|
477 | int virtualKeyCode = Integer.parseInt(string); |
---|
478 | for (VirtualKey key1 : VirtualKey.values()) { |
---|
479 | if (key1.virtualKeyCode == virtualKeyCode) { |
---|
480 | return key1; |
---|
481 | } |
---|
482 | } |
---|
483 | |
---|
484 | throw new IllegalArgumentException("there is no virtual key with id " + string); |
---|
485 | } |
---|
486 | |
---|
487 | /** |
---|
488 | * <p> |
---|
489 | * Returns the VirtualKey associated with an integer. |
---|
490 | * </p> |
---|
491 | * |
---|
492 | * @param number |
---|
493 | * integer to which the according VirtualKey is returned |
---|
494 | * @return the VirtualKey |
---|
495 | * @throws IllegalArgumentException |
---|
496 | * thrown if there is no VirtualKey that correlates to number |
---|
497 | */ |
---|
498 | public static VirtualKey valueOf(int number) { |
---|
499 | for (VirtualKey virtualKey : VirtualKey.values()) { |
---|
500 | if (virtualKey.virtualKeyCode == number) { |
---|
501 | return virtualKey; |
---|
502 | } |
---|
503 | } |
---|
504 | |
---|
505 | throw new IllegalArgumentException("there is no virtual key with number " + number); |
---|
506 | } |
---|
507 | |
---|
508 | } |
---|