JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
KeyEvent.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright (c) 2010 JogAmp Community. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * - Redistribution of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistribution in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any kind. ALL
21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 */
34
35package com.jogamp.newt.event;
36
37import com.jogamp.common.util.Bitfield;
38
39/**
40 * <a name="eventDelivery"><h5>KeyEvent Delivery</h5></a>
41 *
42 * Key events are delivered in the following order:
43 * <p>
44 * <table border="0">
45 * <tr><th>#</th><th>Event Type</th> <th>Constraints</th> <th>Notes</th></tr>
46 * <tr><td>1</td><td>{@link #EVENT_KEY_PRESSED} </td><td> <i> excluding {@link #isAutoRepeat() auto-repeat}-{@link #isModifierKey() modifier} keys</i></td><td></td></tr>
47 * <tr><td>2</td><td>{@link #EVENT_KEY_RELEASED} </td><td> <i> excluding {@link #isAutoRepeat() auto-repeat}-{@link #isModifierKey() modifier} keys</i></td><td></td></tr>
48 * </table>
49 * </p>
50 * In case the native platform does not
51 * deliver keyboard events in the above order or skip events,
52 * the NEWT driver will reorder and inject synthetic events if required.
53 * <p>
54 * Besides regular modifiers like {@link InputEvent#SHIFT_MASK} etc.,
55 * the {@link InputEvent#AUTOREPEAT_MASK} bit is added if repetition is detected, following above constraints.
56 * </p>
57 * <p>
58 * Auto-Repeat shall behave as follow:
59 * <pre>
60 P = pressed, R = released
61 0 = normal, 1 = auto-repeat
62
63 P(0), [ R(1), P(1), R(1), ..], R(0)
64 * </pre>
65 * The idea is if you mask out auto-repeat in your event listener
66 * you just get one long pressed P/R tuple for {@link #isPrintableKey() printable} and {@link #isActionKey() Action} keys.
67 * </p>
68 * <p>
69 * {@link #isActionKey() Action} keys will produce {@link #EVENT_KEY_PRESSED pressed}
70 * and {@link #EVENT_KEY_RELEASED released} events including {@link #isAutoRepeat() auto-repeat}.
71 * </p>
72 * <p>
73 * {@link #isPrintableKey() Printable} keys will produce {@link #EVENT_KEY_PRESSED pressed} and {@link #EVENT_KEY_RELEASED released} events.
74 * </p>
75 * <p>
76 * {@link #isModifierKey() Modifier} keys will produce {@link #EVENT_KEY_PRESSED pressed} and {@link #EVENT_KEY_RELEASED released} events
77 * excluding {@link #isAutoRepeat() auto-repeat}.
78 * They will also influence subsequent event's {@link #getModifiers() modifier} bits while pressed.
79 * </p>
80 *
81 * <a name="unicodeMapping"><h5>Unicode Mapping</h5></a>
82 * <p>
83 * {@link #getKeyChar() Key-chars}, as well as
84 * {@link #isPrintableKey() printable} {@link #getKeyCode() key-codes} and {@link #getKeySymbol() key-symbols}
85 * use the UTF-16 unicode space w/o collision.
86 *
87 * </p>
88 * <p>
89 * Non-{@link #isPrintableKey() printable} {@link #getKeyCode() key-codes} and {@link #getKeySymbol() key-symbols},
90 * i.e. {@link #isModifierKey() modifier-} and {@link #isActionKey() action-}keys,
91 * are mapped to unicode's control and private range and do not collide w/ {@link #isPrintableKey() printable} unicode values
92 * with the following exception.
93 * </p>
94 *
95 * <a name="unicodeCollision"><h5>Unicode Collision</h5></a>
96 * <p>
97 * The following {@link #getKeyCode() Key-code}s and {@link #getKeySymbol() key-symbol}s collide w/ unicode space:<br/>
98 * <table border="1">
99 * <tr><th>unicode range</th> <th>virtual key code</th> <th>unicode character</th></tr>
100 * <tr><td>[0x61 .. 0x78]</td> <td>[{@link #VK_F1}..{@link #VK_F24}]</td> <td>['a'..'x']</td></tr>
101 * </table>
102 * </p>
103 * <p>
104 * Collision was chosen for {@link #getKeyCode() Key-code} and {@link #getKeySymbol() key-symbol} mapping
105 * to allow a minimal code range, i.e. <code>[0..255]</code>.
106 * The reduced code range in turn allows the implementation to utilize fast and small lookup tables,
107 * e.g. to implement a key-press state tracker.
108 * </p>
109 * <pre>
110 * http://www.utf8-chartable.de/unicode-utf8-table.pl
111 * http://www.unicode.org/Public/5.1.0/ucd/PropList.txt
112 * https://en.wikipedia.org/wiki/Mapping_of_Unicode_characters
113 * https://en.wikipedia.org/wiki/Unicode_control_characters
114 * https://en.wikipedia.org/wiki/Private_Use_%28Unicode%29#Private_Use_Areas
115 * </pre>
116 * </p>
117 */
118@SuppressWarnings("serial")
119public class KeyEvent extends InputEvent
120{
121 private KeyEvent(final short eventType, final Object source, final long when, final int modifiers, final short keyCode, final short keySym, final int keySymModMask, final char keyChar) {
122 super(eventType, source, when, modifiers | keySymModMask);
123 this.keyCode=keyCode;
124 this.keySym=keySym;
125 this.keyChar=keyChar;
126 { // cache modifier and action flags
127 byte _flags = 0;
128 if( isPrintableKey(keySym, false) && isPrintableKey((short)keyChar, true) ) {
129 _flags |= F_PRINTABLE_MASK;
130 } else {
131 if( 0 != keySymModMask ) {
132 _flags |= F_MODIFIER_MASK;
133 } else {
134 // A = U - ( P + M )
135 _flags |= F_ACTION_MASK;
136 }
137 }
138 flags = _flags;
139
140 //
141 // Validate flags
142 //
143 final int pma_bits = flags & ( F_PRINTABLE_MASK | F_MODIFIER_MASK | F_ACTION_MASK ) ;
144 final int pma_count = Bitfield.Util.bitCount(pma_bits);
145 if ( 1 != pma_count ) {
146 throw new InternalError("Key must be either of type printable, modifier or action - but it is of "+pma_count+" types: "+this);
147 }
148 }
149 }
150
151 public static KeyEvent create(final short eventType, final Object source, final long when, final int modifiers, final short keyCode, final short keySym, final char keyChar) {
152 return new KeyEvent(eventType, source, when, modifiers, keyCode, keySym, getModifierMask(keySym), keyChar);
153 }
154
155 /**
156 * Returns the <i>UTF-16</i> character reflecting the {@link #getKeySymbol() key symbol}
157 * incl. active {@link #isModifierKey() modifiers}.
158 * @see #getKeySymbol()
159 * @see #getKeyCode()
160 */
161 public final char getKeyChar() {
162 return keyChar;
163 }
164
165 /**
166 * Returns the virtual <i>key symbol</i> reflecting the current <i>keyboard layout</i>.
167 * <p>
168 * For {@link #isPrintableKey() printable keys}, the <i>key symbol</i> is the {@link #isModifierKey() unmodified}
169 * representation of the UTF-16 {@link #getKeyChar() key char}.<br/>
170 * E.g. symbol [{@link #VK_A}, 'A'] for char 'a'.
171 * </p>
172 * @see #isPrintableKey()
173 * @see #getKeyChar()
174 * @see #getKeyCode()
175 */
176 public final short getKeySymbol() {
177 return keySym;
178 }
179
180 /**
181 * Returns the virtual <i>key code</i> using a fixed mapping to the <i>US keyboard layout</i>.
182 * <p>
183 * In contrast to {@link #getKeySymbol() key symbol}, <i>key code</i>
184 * uses a fixed <i>US keyboard layout</i> and therefore is keyboard layout independent.
185 * </p>
186 * <p>
187 * E.g. <i>virtual key code</i> {@link #VK_Y} denotes the same physical key
188 * regardless whether <i>keyboard layout</i> <code>QWERTY</code> or
189 * <code>QWERTZ</code> is active. The {@link #getKeySymbol() key symbol} of the former is
190 * {@link #VK_Y}, where the latter produces {@link #VK_Y}.
191 * </p>
192 * @see #getKeyChar()
193 * @see #getKeySymbol()
194 */
195 public final short getKeyCode() {
196 return keyCode;
197 }
198
199 @Override
200 public final String toString() {
201 return toString(null).toString();
202 }
203
204 @Override
205 public final StringBuilder toString(StringBuilder sb) {
206 if(null == sb) {
207 sb = new StringBuilder();
208 }
209 sb.append("KeyEvent[").append(getEventTypeString(getEventType())).append(", code ").append(toHexString(keyCode)).append(", sym ").append(toHexString(keySym)).append(", char '").append(keyChar).append("' (").append(toHexString((short)keyChar))
210 .append("), printable ").append(isPrintableKey()).append(", modifier ").append(isModifierKey()).append(", action ").append(isActionKey()).append(", ");
211 return super.toString(sb).append("]");
212 }
213
214 public static String getEventTypeString(final short type) {
215 switch(type) {
216 case EVENT_KEY_PRESSED: return "PRESSED";
217 case EVENT_KEY_RELEASED: return "RELEASED";
218 default: return "unknown (" + type + ")";
219 }
220 }
221
222 /**
223 * @param keyChar UTF16 value to map. It is expected that the incoming keyChar value is unshifted and unmodified,
224 * however, lower case a-z is mapped to {@link KeyEvent#VK_A} - {@link KeyEvent#VK_Z}.
225 * @return {@link KeyEvent} virtual key (VK) value.
226 */
227 public static short utf16ToVKey(final char keyChar) {
228 if( 'a' <= keyChar && keyChar <= 'z' ) {
229 return (short) ( ( keyChar - 'a' ) + KeyEvent.VK_A );
230 }
231 return (short) keyChar;
232 }
233
234 /**
235 * Returns <code>true</code> if the given <code>virtualKey</code> represents a modifier key, otherwise <code>false</code>.
236 * <p>
237 * A modifier key is one of {@link #VK_SHIFT}, {@link #VK_CONTROL}, {@link #VK_ALT}, {@link #VK_ALT_GRAPH}, {@link #VK_META}.
238 * </p>
239 */
240 public static boolean isModifierKey(final short vKey) {
241 switch (vKey) {
242 case VK_SHIFT:
243 case VK_CONTROL:
244 case VK_ALT:
245 case VK_ALT_GRAPH:
246 case VK_META:
247 return true;
248 default:
249 return false;
250 }
251 }
252
253 /**
254 * If <code>vKey</code> is a {@link #isModifierKey() modifier key}, method returns the corresponding modifier mask,
255 * otherwise 0.
256 */
257 public static int getModifierMask(final short vKey) {
258 switch (vKey) {
259 case VK_SHIFT:
260 return InputEvent.SHIFT_MASK;
261 case VK_CONTROL:
262 return InputEvent.CTRL_MASK;
263 case VK_ALT:
264 case VK_ALT_GRAPH:
265 return InputEvent.ALT_MASK;
266 case VK_META:
267 return InputEvent.META_MASK;
268 }
269 return 0;
270 }
271
272 /**
273 * Returns <code>true</code> if {@link #getKeySymbol() key symbol} represents a modifier key,
274 * otherwise <code>false</code>.
275 * <p>
276 * See {@link #isModifierKey(short)} for details.
277 * </p>
278 * <p>
279 * Note: Implementation uses a cached value.
280 * </p>
281 */
282 public final boolean isModifierKey() {
283 return 0 != ( F_MODIFIER_MASK & flags ) ;
284 }
285
286 /**
287 * Returns <code>true</code> if {@link #getKeySymbol() key symbol} represents a non-printable and
288 * non-{@link #isModifierKey(short) modifier} action key, otherwise <code>false</code>.
289 * <p>
290 * Hence it is the set A of all keys U w/o printable P and w/o modifiers M:
291 * <code> A = U - ( P + M ) </code>
292 * </p>
293 * @see #isPrintableKey()
294 * @see #isModifierKey()
295 */
296 public final boolean isActionKey() {
297 return 0 != ( F_ACTION_MASK & flags ) ;
298 }
299
300 /**
301 * Returns <code>true</code> if given <code>uniChar</code> represents a printable character,
302 * i.e. a value other than {@link #VK_UNDEFINED} and not a control or non-printable private code.
303 * <p>
304 * A printable character is neither a {@link #isModifierKey(short) modifier key}, nor an {@link #isActionKey(short) action key}.
305 * </p>
306 * <p>
307 * Otherwise returns <code>false</code>.
308 * </p>
309 * <p>
310 * Distinction of key character and virtual key code is made due to <a href="#unicodeCollision">unicode collision</a>.
311 * </p>
312 *
313 * @param uniChar the UTF-16 unicode value, which maybe a virtual key code or key character.
314 * @param isKeyChar true if <code>uniChar</code> is a key character, otherwise a virtual key code
315 */
316 public static boolean isPrintableKey(final short uniChar, final boolean isKeyChar) {
317 if ( VK_BACK_SPACE == uniChar || VK_TAB == uniChar || VK_ENTER == uniChar ) {
318 return true;
319 }
320 if( !isKeyChar ) {
321 if( ( nonPrintableKeys[0].min <= uniChar && uniChar <= nonPrintableKeys[0].max ) ||
322 ( nonPrintableKeys[1].min <= uniChar && uniChar <= nonPrintableKeys[1].max ) ||
323 ( nonPrintableKeys[2].min <= uniChar && uniChar <= nonPrintableKeys[2].max ) ||
324 ( nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) ) {
325 return false;
326 }
327 } else {
328 if( ( nonPrintableKeys[0].inclKeyChar && nonPrintableKeys[0].min <= uniChar && uniChar <= nonPrintableKeys[0].max ) ||
329 ( nonPrintableKeys[1].inclKeyChar && nonPrintableKeys[1].min <= uniChar && uniChar <= nonPrintableKeys[1].max ) ||
330 ( nonPrintableKeys[2].inclKeyChar && nonPrintableKeys[2].min <= uniChar && uniChar <= nonPrintableKeys[2].max ) ||
331 ( nonPrintableKeys[3].inclKeyChar && nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) ) {
332 return false;
333 }
334 }
335 return VK_UNDEFINED != uniChar;
336 }
337
338 /**
339 * Returns <code>true</code> if {@link #getKeySymbol() key symbol} and {@link #getKeyChar() key char}
340 * represents a printable character, i.e. a value other than {@link #VK_UNDEFINED}
341 * and not a control or non-printable private code.
342 * <p>
343 * A printable character is neither a {@link #isModifierKey(short) modifier key}, nor an {@link #isActionKey(short) action key}.
344 * </p>
345 * <p>
346 * Otherwise returns <code>false</code>.
347 * </p>
348 */
349 public final boolean isPrintableKey() {
350 return 0 != ( F_PRINTABLE_MASK & flags ) ;
351 }
352
353 private final short keyCode;
354 private final short keySym;
355 private final char keyChar;
356 private final byte flags;
357 private static final byte F_MODIFIER_MASK = 1 << 0;
358 private static final byte F_ACTION_MASK = 1 << 1;
359 private static final byte F_PRINTABLE_MASK = 1 << 2;
360
361 /** A key has been pressed, excluding {@link #isAutoRepeat() auto-repeat}-{@link #isModifierKey() modifier} keys. */
362 public static final short EVENT_KEY_PRESSED = 300;
363 /** A key has been released, excluding {@link #isAutoRepeat() auto-repeat}-{@link #isModifierKey() modifier} keys. */
364 public static final short EVENT_KEY_RELEASED= 301;
365
366 /**
367 * This value, {@code '\0'}, is used to indicate that the keyChar is unknown or not printable.
368 */
369 public static final char NULL_CHAR = '\0';
370
371 /* Virtual key codes. */
372
373 public static class NonPrintableRange {
374 /** min. unicode value, inclusive */
375 public short min;
376 /** max. unicode value, inclusive */
377 public short max;
378 /** true if valid for keyChar values as well, otherwise only valid for keyCode and keySym due to collision. */
379 public final boolean inclKeyChar;
380 private NonPrintableRange(final short min, final short max, final boolean inclKeyChar) {
381 this.min = min;
382 this.max = max;
383 this.inclKeyChar = inclKeyChar;
384 }
385 };
386 /**
387 * Non printable key ranges, currently fixed to an array of size 4.
388 * <p>
389 * Not included, queried upfront:
390 * <ul>
391 * <li>{@link #VK_BACK_SPACE}</li>
392 * <li>{@link #VK_TAB}</li>
393 * <li>{@link #VK_ENTER}</li>
394 * </ul>
395 * </p>
396 */
397 public final static NonPrintableRange[] nonPrintableKeys = {
398 new NonPrintableRange( (short)0x0000, (short)0x001F, true ), // Unicode: Non printable controls: [0x00 - 0x1F], see exclusion above
399 new NonPrintableRange( (short)0x0061, (short)0x0078, false), // Small 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym - Re-used for Fn (collision)
400 new NonPrintableRange( (short)0x008F, (short)0x009F, true ), // Unicode: Non printable controls: [0x7F - 0x9F], Numpad keys [0x7F - 0x8E] are printable!
401 new NonPrintableRange( (short)0xE000, (short)0xF8FF, true ) // Unicode: Private 0xE000 - 0xF8FF (Marked Non-Printable)
402 };
403
404 //
405 // Unicode: Non printable controls: [0x00 - 0x1F]
406 //
407
408 /**
409 * This value, {@value}, is used to indicate that the keyCode is unknown.
410 */
411 public static final short VK_UNDEFINED = (short) 0x0;
412
413 static final short VK_FREE01 = (short) 0x01;
414
415 /** Constant for the HOME function key. ASCII: Start Of Text. */
416 public static final short VK_HOME = (short) 0x02;
417
418 /** Constant for the END function key. ASCII: End Of Text. */
419 public static final short VK_END = (short) 0x03;
420
421 /** Constant for the END function key. ASCII: End Of Transmission. */
422 public static final short VK_FINAL = (short) 0x04;
423
424 /** Constant for the PRINT function key. ASCII: Enquiry. */
425 public static final short VK_PRINTSCREEN = (short) 0x05;
426
427 static final short VK_FREE06 = (short) 0x06;
428 static final short VK_FREE07 = (short) 0x07;
429
430 /** Constant for the BACK SPACE key "\b", matching ASCII. Printable! */
431 public static final short VK_BACK_SPACE = (short) 0x08;
432
433 /** Constant for the HORIZ TAB key "\t", matching ASCII. Printable! */
434 public static final short VK_TAB = (short) 0x09;
435
436 /** LINE_FEED "\n", matching ASCII, n/a on keyboard. */
437 static final short VK_FREE0A = (short) 0x0A;
438
439 /** Constant for the PAGE DOWN function key. ASCII: Vertical Tabulation. */
440 public static final short VK_PAGE_DOWN = (short) 0x0B;
441
442 /** Constant for the CLEAR key, i.e. FORM FEED, matching ASCII. */
443 public static final short VK_CLEAR = (short) 0x0C;
444
445 /** Constant for the ENTER key, i.e. CARRIAGE RETURN, matching ASCII. Printable! */
446 public static final short VK_ENTER = (short) 0x0D;
447
448 static final short VK_FREE0E = (short) 0x0E;
449
450 /** Constant for the CTRL function key. ASCII: shift-in. */
451 public static final short VK_SHIFT = (short) 0x0F;
452
453 /** Constant for the PAGE UP function key. ASCII: Data Link Escape. */
454 public static final short VK_PAGE_UP = (short) 0x10;
455
456 /** Constant for the CTRL function key. ASCII: device-ctrl-one. */
457 public static final short VK_CONTROL = (short) 0x11;
458
459 /** Constant for the left ALT function key. ASCII: device-ctrl-two. */
460 public static final short VK_ALT = (short) 0x12;
461
462 /** Constant for the ALT_GRAPH function key, i.e. right ALT key. ASCII: device-ctrl-three. */
463 public static final short VK_ALT_GRAPH = (short) 0x13;
464
465 /** Constant for the CAPS LOCK function key. ASCII: device-ctrl-four. */
466 public static final short VK_CAPS_LOCK = (short) 0x14;
467
468 static final short VK_FREE15 = (short) 0x15;
469
470 /** Constant for the PAUSE function key. ASCII: sync-idle. */
471 public static final short VK_PAUSE = (short) 0x16;
472
473 /** <b>scroll lock</b> key. ASCII: End Of Transmission Block. */
474 public static final short VK_SCROLL_LOCK = (short) 0x17;
475
476 /** Constant for the CANCEL function key. ASCII: Cancel. */
477 public static final short VK_CANCEL = (short) 0x18;
478
479 static final short VK_FREE19 = (short) 0x19;
480
481 /** Constant for the INSERT function key. ASCII: Substitute. */
482 public static final short VK_INSERT = (short) 0x1A;
483
484 /** Constant for the ESCAPE function key. ASCII: Escape. */
485 public static final short VK_ESCAPE = (short) 0x1B;
486
487 /** Constant for the Convert function key, Japanese "henkan". ASCII: File Separator. */
488 public static final short VK_CONVERT = (short) 0x1C;
489
490 /** Constant for the Don't Convert function key, Japanese "muhenkan". ASCII: Group Separator.*/
491 public static final short VK_NONCONVERT = (short) 0x1D;
492
493 /** Constant for the Accept or Commit function key, Japanese "kakutei". ASCII: Record Separator.*/
494 public static final short VK_ACCEPT = (short) 0x1E;
495
496 /** Constant for the Mode Change (?). ASCII: Unit Separator.*/
497 public static final short VK_MODECHANGE = (short) 0x1F;
498
499 //
500 // Unicode: Printable [0x20 - 0x7E]
501 // NOTE: Collision of 'a' - 'x' [0x61 .. 0x78], used for keyCode/keySym Fn function keys
502 //
503
504 /** Constant for the SPACE function key. ASCII: SPACE. */
505 public static final short VK_SPACE = (short) 0x20;
506
507 /** Constant for the "!" key. */
508 public static final short VK_EXCLAMATION_MARK = (short) 0x21;
509
510 /** Constant for the """ key. */
511 public static final short VK_QUOTEDBL = (short) 0x22;
512
513 /** Constant for the "#" key. */
514 public static final short VK_NUMBER_SIGN = (short) 0x23;
515
516 /** Constant for the "$" key. */
517 public static final short VK_DOLLAR = (short) 0x24;
518
519 /** Constant for the "%" key. */
520 public static final short VK_PERCENT = (short) 0x25;
521
522 /** Constant for the "&" key. */
523 public static final short VK_AMPERSAND = (short) 0x26;
524
525 /** Constant for the "'" key. */
526 public static final short VK_QUOTE = (short) 0x27;
527
528 /** Constant for the "(" key. */
529 public static final short VK_LEFT_PARENTHESIS = (short) 0x28;
530
531 /** Constant for the ")" key. */
532 public static final short VK_RIGHT_PARENTHESIS = (short) 0x29;
533
534 /** Constant for the "*" key */
535 public static final short VK_ASTERISK = (short) 0x2A;
536
537 /** Constant for the "+" key. */
538 public static final short VK_PLUS = (short) 0x2B;
539
540 /** Constant for the comma key, "," */
541 public static final short VK_COMMA = (short) 0x2C;
542
543 /** Constant for the minus key, "-" */
544 public static final short VK_MINUS = (short) 0x2D;
545
546 /** Constant for the period key, "." */
547 public static final short VK_PERIOD = (short) 0x2E;
548
549 /** Constant for the forward slash key, "/" */
550 public static final short VK_SLASH = (short) 0x2F;
551
552 /** VK_0 thru VK_9 are the same as UTF16/ASCII '0' thru '9' [0x30 - 0x39] */
553 public static final short VK_0 = (short) 0x30;
554 /** See {@link #VK_0}. */
555 public static final short VK_1 = (short) 0x31;
556 /** See {@link #VK_0}. */
557 public static final short VK_2 = (short) 0x32;
558 /** See {@link #VK_0}. */
559 public static final short VK_3 = (short) 0x33;
560 /** See {@link #VK_0}. */
561 public static final short VK_4 = (short) 0x34;
562 /** See {@link #VK_0}. */
563 public static final short VK_5 = (short) 0x35;
564 /** See {@link #VK_0}. */
565 public static final short VK_6 = (short) 0x36;
566 /** See {@link #VK_0}. */
567 public static final short VK_7 = (short) 0x37;
568 /** See {@link #VK_0}. */
569 public static final short VK_8 = (short) 0x38;
570 /** See {@link #VK_0}. */
571 public static final short VK_9 = (short) 0x39;
572
573 /** Constant for the ":" key. */
574 public static final short VK_COLON = (short) 0x3A;
575
576 /** Constant for the semicolon key, ";" */
577 public static final short VK_SEMICOLON = (short) 0x3B;
578
579 /** Constant for the equals key, "<" */
580 public static final short VK_LESS = (short) 0x3C;
581
582 /** Constant for the equals key, "=" */
583 public static final short VK_EQUALS = (short) 0x3D;
584
585 /** Constant for the equals key, ">" */
586 public static final short VK_GREATER = (short) 0x3E;
587
588 /** Constant for the equals key, "?" */
589 public static final short VK_QUESTIONMARK = (short) 0x3F;
590
591 /** Constant for the equals key, "@" */
592 public static final short VK_AT = (short) 0x40;
593
594 /** VK_A thru VK_Z are the same as Capital UTF16/ASCII 'A' thru 'Z' (0x41 - 0x5A) */
595 public static final short VK_A = (short) 0x41;
596 /** See {@link #VK_A}. */
597 public static final short VK_B = (short) 0x42;
598 /** See {@link #VK_A}. */
599 public static final short VK_C = (short) 0x43;
600 /** See {@link #VK_A}. */
601 public static final short VK_D = (short) 0x44;
602 /** See {@link #VK_A}. */
603 public static final short VK_E = (short) 0x45;
604 /** See {@link #VK_A}. */
605 public static final short VK_F = (short) 0x46;
606 /** See {@link #VK_A}. */
607 public static final short VK_G = (short) 0x47;
608 /** See {@link #VK_A}. */
609 public static final short VK_H = (short) 0x48;
610 /** See {@link #VK_A}. */
611 public static final short VK_I = (short) 0x49;
612 /** See {@link #VK_A}. */
613 public static final short VK_J = (short) 0x4A;
614 /** See {@link #VK_A}. */
615 public static final short VK_K = (short) 0x4B;
616 /** See {@link #VK_A}. */
617 public static final short VK_L = (short) 0x4C;
618 /** See {@link #VK_A}. */
619 public static final short VK_M = (short) 0x4D;
620 /** See {@link #VK_A}. */
621 public static final short VK_N = (short) 0x4E;
622 /** See {@link #VK_A}. */
623 public static final short VK_O = (short) 0x4F;
624 /** See {@link #VK_A}. */
625 public static final short VK_P = (short) 0x50;
626 /** See {@link #VK_A}. */
627 public static final short VK_Q = (short) 0x51;
628 /** See {@link #VK_A}. */
629 public static final short VK_R = (short) 0x52;
630 /** See {@link #VK_A}. */
631 public static final short VK_S = (short) 0x53;
632 /** See {@link #VK_A}. */
633 public static final short VK_T = (short) 0x54;
634 /** See {@link #VK_A}. */
635 public static final short VK_U = (short) 0x55;
636 /** See {@link #VK_A}. */
637 public static final short VK_V = (short) 0x56;
638 /** See {@link #VK_A}. */
639 public static final short VK_W = (short) 0x57;
640 /** See {@link #VK_A}. */
641 public static final short VK_X = (short) 0x58;
642 /** See {@link #VK_A}. */
643 public static final short VK_Y = (short) 0x59;
644 /** See {@link #VK_A}. */
645 public static final short VK_Z = (short) 0x5A;
646
647 /** Constant for the open bracket key, "[" */
648 public static final short VK_OPEN_BRACKET = (short) 0x5B;
649
650 /**Constant for the back slash key, "\" */
651 public static final short VK_BACK_SLASH = (short) 0x5C;
652
653 /** Constant for the close bracket key, "]" */
654 public static final short VK_CLOSE_BRACKET = (short) 0x5D;
655
656 /** Constant for the "^" key. */
657 public static final short VK_CIRCUMFLEX = (short) 0x5E;
658
659 /** Constant for the "_" key */
660 public static final short VK_UNDERSCORE = (short) 0x5F;
661
662 /** Constant for the "`" key */
663 public static final short VK_BACK_QUOTE = (short) 0x60;
664
665 /** Small UTF/ASCII 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym. */
666
667 /**
668 * Constant for the F<i>n</i> function keys.
669 * <p>
670 * F1..F24, i.e. F<i>n</i>, are mapped from on <code>0x60+n</code> -> <code>[0x61 .. 0x78]</code>.
671 * </p>
672 * <p>
673 * <b>Warning:</b> The F<i>n</i> function keys <b>do collide</b> with unicode characters small 'a' thru 'x'!<br/>
674 * See <a href="#unicodeCollision">Unicode Collision</a> for details.
675 * </p>
676 */
677 public static final short VK_F1 = (short) ( 0x60+ 1 );
678
679 /** Constant for the F2 function key. See {@link #VK_F1}. */
680 public static final short VK_F2 = (short) ( 0x60+ 2 );
681
682 /** Constant for the F3 function key. See {@link #VK_F1}. */
683 public static final short VK_F3 = (short) ( 0x60+ 3 );
684
685 /** Constant for the F4 function key. See {@link #VK_F1}. */
686 public static final short VK_F4 = (short) ( 0x60+ 4 );
687
688 /** Constant for the F5 function key. See {@link #VK_F1}. */
689 public static final short VK_F5 = (short) ( 0x60+ 5 );
690
691 /** Constant for the F6 function key. See {@link #VK_F1}. */
692 public static final short VK_F6 = (short) ( 0x60+ 6 );
693
694 /** Constant for the F7 function key. See {@link #VK_F1}. */
695 public static final short VK_F7 = (short) ( 0x60+ 7 );
696
697 /** Constant for the F8 function key. See {@link #VK_F1}. */
698 public static final short VK_F8 = (short) ( 0x60+ 8 );
699
700 /** Constant for the F9 function key. See {@link #VK_F1}. */
701 public static final short VK_F9 = (short) ( 0x60+ 9 );
702
703 /** Constant for the F11 function key. See {@link #VK_F1}. */
704 public static final short VK_F10 = (short) ( 0x60+10 );
705
706 /** Constant for the F11 function key. See {@link #VK_F1}. */
707 public static final short VK_F11 = (short) ( 0x60+11 );
708
709 /** Constant for the F12 function key. See {@link #VK_F1}.*/
710 public static final short VK_F12 = (short) ( 0x60+12 );
711
712 /** Constant for the F13 function key. See {@link #VK_F1}. */
713 public static final short VK_F13 = (short) ( 0x60+13 );
714
715 /** Constant for the F14 function key. See {@link #VK_F1}. */
716 public static final short VK_F14 = (short) ( 0x60+14 );
717
718 /** Constant for the F15 function key. See {@link #VK_F1}. */
719 public static final short VK_F15 = (short) ( 0x60+15 );
720
721 /** Constant for the F16 function key. See {@link #VK_F1}. */
722 public static final short VK_F16 = (short) ( 0x60+16 );
723
724 /** Constant for the F17 function key. See {@link #VK_F1}. */
725 public static final short VK_F17 = (short) ( 0x60+17 );
726
727 /** Constant for the F18 function key. See {@link #VK_F1}. */
728 public static final short VK_F18 = (short) ( 0x60+18 );
729
730 /** Constant for the F19 function key. See {@link #VK_F1}. */
731 public static final short VK_F19 = (short) ( 0x60+19 );
732
733 /** Constant for the F20 function key. See {@link #VK_F1}. */
734 public static final short VK_F20 = (short) ( 0x60+20 );
735
736 /** Constant for the F21 function key. See {@link #VK_F1}. */
737 public static final short VK_F21 = (short) ( 0x60+21 );
738
739 /** Constant for the F22 function key. See {@link #VK_F1}. */
740 public static final short VK_F22 = (short) ( 0x60+22 );
741
742 /** Constant for the F23 function key. See {@link #VK_F1}. */
743 public static final short VK_F23 = (short) ( 0x60+23 );
744
745 /** Constant for the F24 function key. See {@link #VK_F1}. */
746 public static final short VK_F24 = (short) ( 0x60+24 );
747
748
749 /** Constant for the "{" key */
750 public static final short VK_LEFT_BRACE = (short) 0x7B;
751 /** Constant for the "|" key */
752 public static final short VK_PIPE = (short) 0x7C;
753 /** Constant for the "}" key */
754 public static final short VK_RIGHT_BRACE = (short) 0x7D;
755
756 /** Constant for the "~" key, matching ASCII */
757 public static final short VK_TILDE = (short) 0x7E;
758
759 //
760 // Unicode: Non printable controls: [0x7F - 0x9F]
761 //
762 // Numpad keys [0x7F - 0x8E] are printable
763 //
764
765 /** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
766 public static final short VK_SEPARATOR = (short) 0x7F;
767
768 /** Numeric keypad VK_NUMPAD0 thru VK_NUMPAD9 are mapped to UTF control (0x80 - 0x89). Non printable UTF control. */
769 public static final short VK_NUMPAD0 = (short) 0x80;
770 /** See {@link #VK_NUMPAD0}. */
771 public static final short VK_NUMPAD1 = (short) 0x81;
772 /** See {@link #VK_NUMPAD0}. */
773 public static final short VK_NUMPAD2 = (short) 0x82;
774 /** See {@link #VK_NUMPAD0}. */
775 public static final short VK_NUMPAD3 = (short) 0x83;
776 /** See {@link #VK_NUMPAD0}. */
777 public static final short VK_NUMPAD4 = (short) 0x84;
778 /** See {@link #VK_NUMPAD0}. */
779 public static final short VK_NUMPAD5 = (short) 0x85;
780 /** See {@link #VK_NUMPAD0}. */
781 public static final short VK_NUMPAD6 = (short) 0x86;
782 /** See {@link #VK_NUMPAD0}. */
783 public static final short VK_NUMPAD7 = (short) 0x87;
784 /** See {@link #VK_NUMPAD0}. */
785 public static final short VK_NUMPAD8 = (short) 0x88;
786 /** See {@link #VK_NUMPAD0}. */
787 public static final short VK_NUMPAD9 = (short) 0x89;
788
789 /** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
790 public static final short VK_DECIMAL = (short) 0x8A;
791
792 /** Numeric keypad <b>add</b> key. Non printable UTF control. */
793 public static final short VK_ADD = (short) 0x8B;
794
795 /** Numeric keypad <b>subtract</b> key. Non printable UTF control. */
796 public static final short VK_SUBTRACT = (short) 0x8C;
797
798 /** Numeric keypad <b>multiply</b> key. Non printable UTF control. */
799 public static final short VK_MULTIPLY = (short) 0x8D;
800
801 /** Numeric keypad <b>divide</b> key. Non printable UTF control. */
802 public static final short VK_DIVIDE = (short) 0x8E;
803
804 /** Constant for the DEL key, matching ASCII. Non printable UTF control. */
805 public static final short VK_DELETE = (short) 0x93;
806
807 /** Numeric keypad <b>num lock</b> key. Non printable UTF control. */
808 public static final short VK_NUM_LOCK = (short) 0x94;
809
810 /** Constant for the cursor- or numerical-pad <b>left</b> arrow key. Non printable UTF control. */
811 public static final short VK_LEFT = (short) 0x95;
812
813 /** Constant for the cursor- or numerical-pad <b>up</b> arrow key. Non printable UTF control. */
814 public static final short VK_UP = (short) 0x96;
815
816 /** Constant for the cursor- or numerical-pad <b>right</b> arrow key. Non printable UTF control. */
817 public static final short VK_RIGHT = (short) 0x97;
818
819 /** Constant for the cursor- or numerical pad <b>down</b> arrow key. Non printable UTF control. */
820 public static final short VK_DOWN = (short) 0x98;
821
822 /** Constant for the Context Menu key. Non printable UTF control. */
823 public static final short VK_CONTEXT_MENU = (short) 0x99;
824
825 /**
826 * Constant for the MS "Windows" function key.
827 * It is used for both the left and right version of the key.
828 */
829 public static final short VK_WINDOWS = (short) 0x9A;
830
831 /** Constant for the Meta function key. */
832 public static final short VK_META = (short) 0x9B;
833
834 /** Constant for the Help function key. */
835 public static final short VK_HELP = (short) 0x9C;
836
837 /** Constant for the Compose function key. */
838 public static final short VK_COMPOSE = (short) 0x9D;
839
840 /** Constant for the Begin function key. */
841 public static final short VK_BEGIN = (short) 0x9E;
842
843 /** Constant for the Stop function key. */
844 public static final short VK_STOP = (short) 0x9F;
845
846 //
847 // Unicode: Printable [0x00A0 - 0xDFFF]
848 //
849
850 /** Constant for the inverted exclamation mark key. */
851 public static final short VK_INVERTED_EXCLAMATION_MARK = (short) 0xA1;
852
853 /** Constant for the Euro currency sign key. */
854 public static final short VK_EURO_SIGN = (short) 0x20AC;
855
856 //
857 // Unicode: Private 0xE000 - 0xF8FF (Marked Non-Printable)
858 //
859
860 /* for Sun keyboards */
861 public static final short VK_CUT = (short) 0xF879;
862 public static final short VK_COPY = (short) 0xF87A;
863 public static final short VK_PASTE = (short) 0xF87B;
864 public static final short VK_UNDO = (short) 0xF87C;
865 public static final short VK_AGAIN = (short) 0xF87D;
866 public static final short VK_FIND = (short) 0xF87E;
867 public static final short VK_PROPS = (short) 0xF87F;
868
869 /* for input method support on Asian Keyboards */
870
871 /**
872 * Constant for the input method on/off key.
873 */
874 /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */
875 public static final short VK_INPUT_METHOD_ON_OFF = (short) 0xF890;
876
877 /**
878 * Constant for the Code Input function key.
879 */
880 /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */
881 public static final short VK_CODE_INPUT = (short) 0xF891;
882
883 /**
884 * Constant for the Roman Characters function key.
885 */
886 /* Japanese PC 106 keyboard: roumaji */
887 public static final short VK_ROMAN_CHARACTERS = (short) 0xF892;
888
889 /**
890 * Constant for the All Candidates function key.
891 */
892 /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */
893 public static final short VK_ALL_CANDIDATES = (short) 0xF893;
894
895 /**
896 * Constant for the Previous Candidate function key.
897 */
898 /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */
899 public static final short VK_PREVIOUS_CANDIDATE = (short) 0xF894;
900
901 /**
902 * Constant for the Alphanumeric function key.
903 */
904 /* Japanese PC 106 keyboard: eisuu */
905 public static final short VK_ALPHANUMERIC = (short) 0xF895;
906
907 /**
908 * Constant for the Katakana function key.
909 */
910 /* Japanese PC 106 keyboard: katakana */
911 public static final short VK_KATAKANA = (short) 0xF896;
912
913 /**
914 * Constant for the Hiragana function key.
915 */
916 /* Japanese PC 106 keyboard: hiragana */
917 public static final short VK_HIRAGANA = (short) 0xF897;
918
919 /**
920 * Constant for the Full-Width Characters function key.
921 */
922 /* Japanese PC 106 keyboard: zenkaku */
923 public static final short VK_FULL_WIDTH = (short) 0xF898;
924
925 /**
926 * Constant for the Half-Width Characters function key.
927 */
928 /* Japanese PC 106 keyboard: hankaku */
929 public static final short VK_HALF_WIDTH = (short) 0xF89A;
930
931 /**
932 * Constant for the Japanese-Katakana function key.
933 * This key switches to a Japanese input method and selects its Katakana input mode.
934 */
935 /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */
936 public static final short VK_JAPANESE_KATAKANA = (short) 0xF89B;
937
938 /**
939 * Constant for the Japanese-Hiragana function key.
940 * This key switches to a Japanese input method and selects its Hiragana input mode.
941 */
942 /* Japanese Macintosh keyboard */
943 public static final short VK_JAPANESE_HIRAGANA = (short) 0xF89C;
944
945 /**
946 * Constant for the Japanese-Roman function key.
947 * This key switches to a Japanese input method and selects its Roman-Direct input mode.
948 */
949 /* Japanese Macintosh keyboard */
950 public static final short VK_JAPANESE_ROMAN = (short) 0xF89D;
951
952 /**
953 * Constant for the locking Kana function key.
954 * This key locks the keyboard into a Kana layout.
955 */
956 /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */
957 public static final short VK_KANA_LOCK = (short) 0xF89F;
958
959 /**
960 * Constant for Keyboard became invisible, e.g. Android's soft keyboard Back button hit while keyboard is visible.
961 */
962 public static final short VK_KEYBOARD_INVISIBLE = (short) 0xF8FF;
963
964}
965
final boolean inclKeyChar
true if valid for keyChar values as well, otherwise only valid for keyCode and keySym due to collisio...
Definition: KeyEvent.java:379
final boolean isPrintableKey()
Returns true if key symbol and key char represents a printable character, i.e.
Definition: KeyEvent.java:349
final StringBuilder toString(StringBuilder sb)
Definition: KeyEvent.java:205
static final short VK_A
VK_A thru VK_Z are the same as Capital UTF16/ASCII 'A' thru 'Z' (0x41 - 0x5A)
Definition: KeyEvent.java:595
static String getEventTypeString(final short type)
Definition: KeyEvent.java:214
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
Definition: KeyEvent.java:161
final boolean isModifierKey()
Returns true if key symbol represents a modifier key, otherwise false.
Definition: KeyEvent.java:282
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
static int getModifierMask(final short vKey)
If vKey is a modifier key, method returns the corresponding modifier mask, otherwise 0.
Definition: KeyEvent.java:257
static boolean isModifierKey(final short vKey)
Returns true if the given virtualKey represents a modifier key, otherwise false.
Definition: KeyEvent.java:240
final boolean isActionKey()
Returns true if key symbol represents a non-printable and non-modifier action key,...
Definition: KeyEvent.java:296
static KeyEvent create(final short eventType, final Object source, final long when, final int modifiers, final short keyCode, final short keySym, final char keyChar)
Definition: KeyEvent.java:151
final short getKeyCode()
Returns the virtual key code using a fixed mapping to the US keyboard layout.
Definition: KeyEvent.java:195
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
Definition: KeyEvent.java:316
static short utf16ToVKey(final char keyChar)
Definition: KeyEvent.java:227