summaryrefslogtreecommitdiff
path: root/java/awt/event/KeyEvent.java
blob: e37710971d7276514d64caa7c07f0bdfc2bf7b38 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/* KeyEvent.java -- Event for key presses.
   Copyright (C) 1999 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */


package java.awt.event;

import java.awt.Component;

/**
  * This event is generated when a key is pressed or released.
  *
  * @author Aaron M. Renn (arenn@urbanophile.com)
  */
public class KeyEvent extends InputEvent implements java.io.Serializable
{

/*
 * Static Variables
 */

/**
  * This is the first id in the range of event ids used by this class.
  */
public static final int KEY_FIRST = 400;

/**
  * This is the last id in the range of event ids used by this class.
  */
public static final int KEY_LAST = 402;

/**
  * This event id indicates a key was typed, which is a key press
  * followed by a key release.
  */
public static final int KEY_TYPED = 400;

/**
  * This event id indicates a key was pressed.
  */
public static final int KEY_PRESSED = 401;

/**
  * This event it indicates a key was released.
  */
public static final int KEY_RELEASED = 402;

// Virtual key constants, document later

public static final int VK_0 = '0';
public static final int VK_1 = '1';
public static final int VK_2 = '2';
public static final int VK_3 = '3';
public static final int VK_4 = '4';
public static final int VK_5 = '5';
public static final int VK_6 = '6';
public static final int VK_7 = '7';
public static final int VK_8 = '8';
public static final int VK_9 = '9';

public static final int VK_A = 'A';
public static final int VK_B = 'B';
public static final int VK_C = 'C';
public static final int VK_D = 'D';
public static final int VK_E = 'E';
public static final int VK_F = 'F';
public static final int VK_G = 'G';
public static final int VK_H = 'H';
public static final int VK_I = 'I';
public static final int VK_J = 'J';
public static final int VK_K = 'K';
public static final int VK_L = 'L';
public static final int VK_M = 'M';
public static final int VK_N = 'N';
public static final int VK_O = 'O';
public static final int VK_P = 'P';
public static final int VK_Q = 'Q';
public static final int VK_R = 'R';
public static final int VK_S = 'S';
public static final int VK_T = 'T';
public static final int VK_U = 'U';
public static final int VK_V = 'V';
public static final int VK_W = 'W';
public static final int VK_X = 'X';
public static final int VK_Y = 'Y';
public static final int VK_Z = 'Z';

public static final int VK_AMPERSAND = '&';
public static final int VK_ASTERISK = '*';
public static final int VK_AT = '@';
public static final int VK_BACK_QUOTE = '`';
public static final int VK_BACK_SLASH = '\\';
public static final int VK_BACK_SPACE = '\b';
public static final int VK_BRACELEFT = '{';
public static final int VK_BRACERIGHT = '}';
public static final int VK_CIRCUMFLEX = '^';
public static final int VK_OPEN_BRACKET = '[';
public static final int VK_CLOSE_BRACKET = ']';
public static final int VK_COLON = ':';
public static final int VK_COMMA = ',';
public static final int VK_DOLLAR = '$';
public static final int VK_ENTER = '\n';
public static final int VK_EQUALS = '=';
public static final int VK_EXCLAMATION_POINT = '!';
public static final int VK_GREATER = '>';
public static final int VK_LESS = '<';
public static final int VK_LEFT_PARENTHESIS = '(';
public static final int VK_RIGHT_PARENTHESIS = ')';
public static final int VK_MINUS = '-';
public static final int VK_NUMBER_SIGN = '#';
public static final int VK_PERIOD = '.';
public static final int VK_PLUS = '+';
public static final int VK_QUOTE = '"';
public static final int VK_SEMICOLON = ';';
public static final int VK_SLASH = '/';
public static final int VK_SPACE = ' ';
public static final int VK_TAB = '\t';
public static final int VK_UNDERSCORE = '_';

public static final int VK_F1 = 0x70;
public static final int VK_F2 = 0x71;
public static final int VK_F3 = 0x72;
public static final int VK_F4 = 0x73;
public static final int VK_F5 = 0x74;
public static final int VK_F6 = 0x75;
public static final int VK_F7 = 0x76;
public static final int VK_F8 = 0x77;
public static final int VK_F9 = 0x78;
public static final int VK_F10 = 0x79;
public static final int VK_F11 = 0x7A;
public static final int VK_F12 = 0x7B;

public static final int VK_NUMPAD0 = 0x60;
public static final int VK_NUMPAD1 = 0x61;
public static final int VK_NUMPAD2 = 0x62;
public static final int VK_NUMPAD3 = 0x63;
public static final int VK_NUMPAD4 = 0x64;
public static final int VK_NUMPAD5 = 0x65;
public static final int VK_NUMPAD6 = 0x66;
public static final int VK_NUMPAD7 = 0x67;
public static final int VK_NUMPAD8 = 0x68;
public static final int VK_NUMPAD9 = 0x69;

public static final int VK_ADD = 0x6B;
public static final int VK_SUBTRACT = 0x6D;
public static final int VK_MULTIPLY = 0x6A;
public static final int VK_DIVIDE = 0x6F;
public static final int VK_DECIMAL = 0x6E;
public static final int VK_SEPARATER = 0x6C;

public static final int VK_LEFT = 0x25;
public static final int VK_RIGHT = 0x27;
public static final int VK_UP = 0x26;
public static final int VK_DOWN = 0x38;

public static final int VK_HOME = 0x24;
public static final int VK_END = 0x23;
public static final int VK_PAGE_UP = 0x21;
public static final int VK_PAGE_DOWN = 0x22;

public static final int VK_ALT = 0x12;
public static final int VK_CANCEL = 0x03;
public static final int VK_CAPS_LOCK = 0x14;
public static final int VK_CLEAR = 0x0C;
public static final int VK_CONTROL = 0x11;
public static final int VK_DELETE = 0x7F;
public static final int VK_ESCAPE = 0x1B;
public static final int VK_HELP = 0x9C;
public static final int VK_INSERT = 0x9B;
public static final int VK_META = 0x9D;
public static final int VK_NUM_LOCK = 0x90;
public static final int VK_PAUSE = 0x13;
public static final int VK_PRINTSCREEN = 0x9A;
public static final int VK_SCROLL_LOCK = 0x91;
public static final int VK_SHIFT = 0x10;

public static final int VK_CONVERT = 0x1C;
public static final int VK_NONCONVERT = 0x1D;
public static final int VK_ACCEPT = 0x1E;
public static final int VK_FINAL = 0x18;
public static final int VK_MODECHANGE = 0x1F;

public static final int VK_KANA = 0x15;
public static final int VK_KANJI = 0x19;

public static final int VK_UNDEFINED = 0;
public static final char CHAR_UNDEFINED = 0;

// FIXME: Java 1.2 keys I don't know the code for yet.
/*
public static final int VK_ALL_CANDIDATES =
public static final int VK_ALPHANUMERIC =
public static final int VK_ALT_GRAPH =
public static final int VK_CODE_INPUT =
public static final int VK_COMPOSE =
public static final int VK_COPY =
public static final int VK_CUT = 
public static final int VK_EURO_SIGN =
public static final int VK_FIND =
public static final int VK_FULL_WIDTH =
public static final int VK_HALF_WIDTH
public static final int VK_HIRAGANA =
public static final int VK_INVERTED_EXCLAMATION_POINT =
public static final int VK_JAPANESE_HIRAGANA =
public static final int VK_JAPANESE_KATAKANA =
public static final int VK_JAPANESE_ROMAN =
public static final int VK_KATAKANA =
public static final int VK_PASTE = 
public static final int VK_PREVIOUS_CANDIDATE =
public static final int VK_QUOTEDBL =
public static final int VK_ROMAN_CHARACTERS =
public static final int VK_STOP =

public static final int VK_KP_UP =
public static final int VK_KP_DOWN =
public static final int VK_KP_LEFT =
public static final int VK_KP_RIGHT =

public static final int VK_DEAD_ABOVEDOT =
public static final int VK_DEAD_ABOVERING =
public static final int VK_DEAD_ACUTE =
public static final int VK_DEAD_BREVE =
public static final int VK_DEAD_CARON =
public static final int VK_DEAD_CEDILLA =
public static final int VK_DEAD_CIRCUMFLEX =
public static final int VK_DEAD_DIAERESIS =
public static final int VK_DEAD_DOUBLEACUTE =
public static final int VK_DEAD_GRAVE =
public static final int VK_DEAD_IOTA =
public static final int VK_DEAD_MACRON =
public static final int VK_DEAD_OGONEK =
public static final int VK_DEAD_SEMIVOICED_SOUND =
public static final int VK_DEAD_TILDE =
public static final int VK_DEAD_VOICED_SOUND =

public static final int VK_F13 =
public static final int VK_F14 =
public static final int VK_F15 =
public static final int VK_F16 =
public static final int VK_F17 =
public static final int VK_F18 =
public static final int VK_F19 =
public static final int VK_F20 =
public static final int VK_F21 =
public static final int VK_F22 =
public static final int VK_F23 =
public static final int VK_F24 =
*/

/*************************************************************************/

/*
 * Instance Variables
 */

/**
  * @serial The VK_ code for this key
  */
private int keyCode; 

/**
  * @serial  The Unicode value for this key
  */
private char keyChar;

/*************************************************************************/

/*
 * Static Methods
 */

/**
  * Returns the text name of the event key.
  *
  * @return The text name of the event key.
  */
public static String
getKeyText(int keyCode)
{
  // FIXME: Needs to read values from property file
  return("Unknown");
}

/*************************************************************************/

/**
  * Returns a string indicating the modifier keys in effect.
  *
  * @return A string describing the modifier keys in effect.
  */
public static String
getModifiersText(int modifiers)
{
  // FIXME: Needs to read values from property file
  return("Unknown");
}

/*************************************************************************/

/*
 * Constructors
 */

/**
  * Initializes a new instance of <code>KeyEvent</code> with the specified
  * information.
  *
  * @param source The component that generated this event.
  * @param id The event id.
  * @param when The timestamp when the even occurred.
  * @param modifiers The modifier keys pressed during the event.
  * @param keyCode The integer constant from this class identifying the key.
  * @param keyChar The Unicode value of the key, or 
  * <code>CHAR_UNDEFINED</code> if one does not exist.
  */
public 
KeyEvent(Component source, int id, long when, int modifiers,
         int keyCode, char keyChar)
{
  super(source, id, when, modifiers);
  this.keyCode = keyCode;
  this.keyChar = keyChar;
}
  
/*************************************************************************/

/**
  * Initializes a new instance of <code>KeyEvent</code> with the specified
  * information.
  *
  * @param source The component that generated this event.
  * @param id The event id.
  * @param when The timestamp when the even occurred.
  * @param modifiers The modifier keys pressed during the event.
  * @param keyCode The integer constant from this class identifying the key.
  */
public 
KeyEvent(Component source, int id, long when, int modifiers, int keyCode)
{
  this(source, id, when, modifiers, keyCode, CHAR_UNDEFINED);
}

/*************************************************************************/

/*
 * Instance Variables
 */

/**
  * Returns the key code for the event key.  This will be one of the VK_
  * constants defined in this class.
  *
  * @return The key code for this event.
  */
public int
getKeyCode()
{
  return(keyCode);
}

/*************************************************************************/

/**
  * Sets the key code for this event.  This must be one of the VK_
  * constants defined in this class.
  *
  * @param keyCode The new key code for this event.
  */
public void
setKeyCode(int keyCode)
{
  this.keyCode = keyCode;
}

/*************************************************************************/

/**
  * Returns the Unicode value for the event key.  This will be 
  * <code>CHAR_UNDEFINED</code> if there is no Unicode equivalent for
  * this key.
  *
  * @return The Unicode character for this event.
  */
public char
getKeyChar()
{
  return(keyChar);
}

/*************************************************************************/

/**
  * Sets the Unicode character for this event to the specified value.
  *
  * @param keyChar The new Unicode character for this event.
  */
public void
setKeyChar(char keyChar)
{
  this.keyChar = keyChar;
}

/*************************************************************************/

/**
  * Sets the modifier keys to the specified value.  This should be a union
  * of the bit mask constants from <code>InputEvent</code>.
  *
  * @param modifiers The new modifier value.
  */
public void
setModifiers(int modifiers)
{
  this.modifiers = modifiers;
}

/*************************************************************************/

/**
  * Tests whether or not this key is an action key as defined in
  * <code>java.awt.Event</code>
  *
  * @return <code>true</code> if this is an action key, or <code>false</code>
  * if it is not.
  */
public boolean
isActionKey()
{
  switch(keyCode)
    {
      case VK_F1:
      case VK_F2:
      case VK_F3:
      case VK_F4:
      case VK_F5:
      case VK_F6:
      case VK_F7:
      case VK_F8:
      case VK_F9:
      case VK_F10:
      case VK_F11:
      case VK_F12:
      case VK_PAGE_UP:
      case VK_PAGE_DOWN:
      case VK_HOME:
      case VK_END:
      case VK_PRINTSCREEN:
      case VK_SCROLL_LOCK:
      case VK_NUM_LOCK:
      case VK_PAUSE:
      case VK_INSERT:
        return(true);

      default:
        return(false);
    }
}

/*************************************************************************/

/**
  * Returns a string identifying the event.
  *
  * @return A string identifying the event.
  */
public String
paramString()
{
  return(getClass().getName() + " keyCode=" + getKeyCode() + " modifiers=" +
         getModifiers());
}

} // class KeyEvent