Merge branch 'upstream' into subtree
[nikiroo-utils.git] / TKeypress.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2019 Kevin Lamonte
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29 package jexer;
30
31 /**
32 * This class represents keystrokes.
33 */
34 public class TKeypress {
35
36 // ------------------------------------------------------------------------
37 // Constants --------------------------------------------------------------
38 // ------------------------------------------------------------------------
39
40 // Various special keystrokes
41
42 /**
43 * "No key".
44 */
45 public static final int NONE = 255;
46
47 /**
48 * Function key F1.
49 */
50 public static final int F1 = 1;
51
52 /**
53 * Function key F2.
54 */
55 public static final int F2 = 2;
56
57 /**
58 * Function key F3.
59 */
60 public static final int F3 = 3;
61
62 /**
63 * Function key F4.
64 */
65 public static final int F4 = 4;
66
67 /**
68 * Function key F5.
69 */
70 public static final int F5 = 5;
71
72 /**
73 * Function key F6.
74 */
75 public static final int F6 = 6;
76
77 /**
78 * Function key F7.
79 */
80 public static final int F7 = 7;
81
82 /**
83 * Function key F8.
84 */
85 public static final int F8 = 8;
86
87 /**
88 * Function key F9.
89 */
90 public static final int F9 = 9;
91
92 /**
93 * Function key F10.
94 */
95 public static final int F10 = 10;
96
97 /**
98 * Function key F11.
99 */
100 public static final int F11 = 11;
101
102 /**
103 * Function key F12.
104 */
105 public static final int F12 = 12;
106
107 /**
108 * Home.
109 */
110 public static final int HOME = 20;
111
112 /**
113 * End.
114 */
115 public static final int END = 21;
116
117 /**
118 * Page up.
119 */
120 public static final int PGUP = 22;
121
122 /**
123 * Page down.
124 */
125 public static final int PGDN = 23;
126
127 /**
128 * Insert.
129 */
130 public static final int INS = 24;
131
132 /**
133 * Delete.
134 */
135 public static final int DEL = 25;
136
137 /**
138 * Right arrow.
139 */
140 public static final int RIGHT = 30;
141
142 /**
143 * Left arrow.
144 */
145 public static final int LEFT = 31;
146
147 /**
148 * Up arrow.
149 */
150 public static final int UP = 32;
151
152 /**
153 * Down arrow.
154 */
155 public static final int DOWN = 33;
156
157 /**
158 * Tab.
159 */
160 public static final int TAB = 40;
161
162 /**
163 * Back-tab (shift-tab).
164 */
165 public static final int BTAB = 41;
166
167 /**
168 * Enter.
169 */
170 public static final int ENTER = 42;
171
172 /**
173 * Escape.
174 */
175 public static final int ESC = 43;
176
177 // Special "no-key" keypress, used to ignore undefined keystrokes
178 public static final TKeypress kbNoKey = new TKeypress(true,
179 TKeypress.NONE, ' ', false, false, false);
180
181 // Normal keys
182 public static final TKeypress kbF1 = new TKeypress(true,
183 TKeypress.F1, ' ', false, false, false);
184 public static final TKeypress kbF2 = new TKeypress(true,
185 TKeypress.F2, ' ', false, false, false);
186 public static final TKeypress kbF3 = new TKeypress(true,
187 TKeypress.F3, ' ', false, false, false);
188 public static final TKeypress kbF4 = new TKeypress(true,
189 TKeypress.F4, ' ', false, false, false);
190 public static final TKeypress kbF5 = new TKeypress(true,
191 TKeypress.F5, ' ', false, false, false);
192 public static final TKeypress kbF6 = new TKeypress(true,
193 TKeypress.F6, ' ', false, false, false);
194 public static final TKeypress kbF7 = new TKeypress(true,
195 TKeypress.F7, ' ', false, false, false);
196 public static final TKeypress kbF8 = new TKeypress(true,
197 TKeypress.F8, ' ', false, false, false);
198 public static final TKeypress kbF9 = new TKeypress(true,
199 TKeypress.F9, ' ', false, false, false);
200 public static final TKeypress kbF10 = new TKeypress(true,
201 TKeypress.F10, ' ', false, false, false);
202 public static final TKeypress kbF11 = new TKeypress(true,
203 TKeypress.F11, ' ', false, false, false);
204 public static final TKeypress kbF12 = new TKeypress(true,
205 TKeypress.F12, ' ', false, false, false);
206 public static final TKeypress kbAltF1 = new TKeypress(true,
207 TKeypress.F1, ' ', true, false, false);
208 public static final TKeypress kbAltF2 = new TKeypress(true,
209 TKeypress.F2, ' ', true, false, false);
210 public static final TKeypress kbAltF3 = new TKeypress(true,
211 TKeypress.F3, ' ', true, false, false);
212 public static final TKeypress kbAltF4 = new TKeypress(true,
213 TKeypress.F4, ' ', true, false, false);
214 public static final TKeypress kbAltF5 = new TKeypress(true,
215 TKeypress.F5, ' ', true, false, false);
216 public static final TKeypress kbAltF6 = new TKeypress(true,
217 TKeypress.F6, ' ', true, false, false);
218 public static final TKeypress kbAltF7 = new TKeypress(true,
219 TKeypress.F7, ' ', true, false, false);
220 public static final TKeypress kbAltF8 = new TKeypress(true,
221 TKeypress.F8, ' ', true, false, false);
222 public static final TKeypress kbAltF9 = new TKeypress(true,
223 TKeypress.F9, ' ', true, false, false);
224 public static final TKeypress kbAltF10 = new TKeypress(true,
225 TKeypress.F10, ' ', true, false, false);
226 public static final TKeypress kbAltF11 = new TKeypress(true,
227 TKeypress.F11, ' ', true, false, false);
228 public static final TKeypress kbAltF12 = new TKeypress(true,
229 TKeypress.F12, ' ', true, false, false);
230 public static final TKeypress kbCtrlF1 = new TKeypress(true,
231 TKeypress.F1, ' ', false, true, false);
232 public static final TKeypress kbCtrlF2 = new TKeypress(true,
233 TKeypress.F2, ' ', false, true, false);
234 public static final TKeypress kbCtrlF3 = new TKeypress(true,
235 TKeypress.F3, ' ', false, true, false);
236 public static final TKeypress kbCtrlF4 = new TKeypress(true,
237 TKeypress.F4, ' ', false, true, false);
238 public static final TKeypress kbCtrlF5 = new TKeypress(true,
239 TKeypress.F5, ' ', false, true, false);
240 public static final TKeypress kbCtrlF6 = new TKeypress(true,
241 TKeypress.F6, ' ', false, true, false);
242 public static final TKeypress kbCtrlF7 = new TKeypress(true,
243 TKeypress.F7, ' ', false, true, false);
244 public static final TKeypress kbCtrlF8 = new TKeypress(true,
245 TKeypress.F8, ' ', false, true, false);
246 public static final TKeypress kbCtrlF9 = new TKeypress(true,
247 TKeypress.F9, ' ', false, true, false);
248 public static final TKeypress kbCtrlF10 = new TKeypress(true,
249 TKeypress.F10, ' ', false, true, false);
250 public static final TKeypress kbCtrlF11 = new TKeypress(true,
251 TKeypress.F11, ' ', false, true, false);
252 public static final TKeypress kbCtrlF12 = new TKeypress(true,
253 TKeypress.F12, ' ', false, true, false);
254 public static final TKeypress kbShiftF1 = new TKeypress(true,
255 TKeypress.F1, ' ', false, false, true);
256 public static final TKeypress kbShiftF2 = new TKeypress(true,
257 TKeypress.F2, ' ', false, false, true);
258 public static final TKeypress kbShiftF3 = new TKeypress(true,
259 TKeypress.F3, ' ', false, false, true);
260 public static final TKeypress kbShiftF4 = new TKeypress(true,
261 TKeypress.F4, ' ', false, false, true);
262 public static final TKeypress kbShiftF5 = new TKeypress(true,
263 TKeypress.F5, ' ', false, false, true);
264 public static final TKeypress kbShiftF6 = new TKeypress(true,
265 TKeypress.F6, ' ', false, false, true);
266 public static final TKeypress kbShiftF7 = new TKeypress(true,
267 TKeypress.F7, ' ', false, false, true);
268 public static final TKeypress kbShiftF8 = new TKeypress(true,
269 TKeypress.F8, ' ', false, false, true);
270 public static final TKeypress kbShiftF9 = new TKeypress(true,
271 TKeypress.F9, ' ', false, false, true);
272 public static final TKeypress kbShiftF10 = new TKeypress(true,
273 TKeypress.F10, ' ', false, false, true);
274 public static final TKeypress kbShiftF11 = new TKeypress(true,
275 TKeypress.F11, ' ', false, false, true);
276 public static final TKeypress kbShiftF12 = new TKeypress(true,
277 TKeypress.F12, ' ', false, false, true);
278 public static final TKeypress kbEnter = new TKeypress(true,
279 TKeypress.ENTER, ' ', false, false, false);
280 public static final TKeypress kbTab = new TKeypress(true,
281 TKeypress.TAB, ' ', false, false, false);
282 public static final TKeypress kbEsc = new TKeypress(true,
283 TKeypress.ESC, ' ', false, false, false);
284 public static final TKeypress kbHome = new TKeypress(true,
285 TKeypress.HOME, ' ', false, false, false);
286 public static final TKeypress kbEnd = new TKeypress(true,
287 TKeypress.END, ' ', false, false, false);
288 public static final TKeypress kbPgUp = new TKeypress(true,
289 TKeypress.PGUP, ' ', false, false, false);
290 public static final TKeypress kbPgDn = new TKeypress(true,
291 TKeypress.PGDN, ' ', false, false, false);
292 public static final TKeypress kbIns = new TKeypress(true,
293 TKeypress.INS, ' ', false, false, false);
294 public static final TKeypress kbDel = new TKeypress(true,
295 TKeypress.DEL, ' ', false, false, false);
296 public static final TKeypress kbUp = new TKeypress(true,
297 TKeypress.UP, ' ', false, false, false);
298 public static final TKeypress kbDown = new TKeypress(true,
299 TKeypress.DOWN, ' ', false, false, false);
300 public static final TKeypress kbLeft = new TKeypress(true,
301 TKeypress.LEFT, ' ', false, false, false);
302 public static final TKeypress kbRight = new TKeypress(true,
303 TKeypress.RIGHT, ' ', false, false, false);
304 public static final TKeypress kbAltEnter = new TKeypress(true,
305 TKeypress.ENTER, ' ', true, false, false);
306 public static final TKeypress kbAltTab = new TKeypress(true,
307 TKeypress.TAB, ' ', true, false, false);
308 public static final TKeypress kbAltEsc = new TKeypress(true,
309 TKeypress.ESC, ' ', true, false, false);
310 public static final TKeypress kbAltHome = new TKeypress(true,
311 TKeypress.HOME, ' ', true, false, false);
312 public static final TKeypress kbAltEnd = new TKeypress(true,
313 TKeypress.END, ' ', true, false, false);
314 public static final TKeypress kbAltPgUp = new TKeypress(true,
315 TKeypress.PGUP, ' ', true, false, false);
316 public static final TKeypress kbAltPgDn = new TKeypress(true,
317 TKeypress.PGDN, ' ', true, false, false);
318 public static final TKeypress kbAltIns = new TKeypress(true,
319 TKeypress.INS, ' ', true, false, false);
320 public static final TKeypress kbAltDel = new TKeypress(true,
321 TKeypress.DEL, ' ', true, false, false);
322 public static final TKeypress kbAltUp = new TKeypress(true,
323 TKeypress.UP, ' ', true, false, false);
324 public static final TKeypress kbAltDown = new TKeypress(true,
325 TKeypress.DOWN, ' ', true, false, false);
326 public static final TKeypress kbAltLeft = new TKeypress(true,
327 TKeypress.LEFT, ' ', true, false, false);
328 public static final TKeypress kbAltRight = new TKeypress(true,
329 TKeypress.RIGHT, ' ', true, false, false);
330 public static final TKeypress kbCtrlEnter = new TKeypress(true,
331 TKeypress.ENTER, ' ', false, true, false);
332 public static final TKeypress kbCtrlTab = new TKeypress(true,
333 TKeypress.TAB, ' ', false, true, false);
334 public static final TKeypress kbCtrlEsc = new TKeypress(true,
335 TKeypress.ESC, ' ', false, true, false);
336 public static final TKeypress kbCtrlHome = new TKeypress(true,
337 TKeypress.HOME, ' ', false, true, false);
338 public static final TKeypress kbCtrlEnd = new TKeypress(true,
339 TKeypress.END, ' ', false, true, false);
340 public static final TKeypress kbCtrlPgUp = new TKeypress(true,
341 TKeypress.PGUP, ' ', false, true, false);
342 public static final TKeypress kbCtrlPgDn = new TKeypress(true,
343 TKeypress.PGDN, ' ', false, true, false);
344 public static final TKeypress kbCtrlIns = new TKeypress(true,
345 TKeypress.INS, ' ', false, true, false);
346 public static final TKeypress kbCtrlDel = new TKeypress(true,
347 TKeypress.DEL, ' ', false, true, false);
348 public static final TKeypress kbCtrlUp = new TKeypress(true,
349 TKeypress.UP, ' ', false, true, false);
350 public static final TKeypress kbCtrlDown = new TKeypress(true,
351 TKeypress.DOWN, ' ', false, true, false);
352 public static final TKeypress kbCtrlLeft = new TKeypress(true,
353 TKeypress.LEFT, ' ', false, true, false);
354 public static final TKeypress kbCtrlRight = new TKeypress(true,
355 TKeypress.RIGHT, ' ', false, true, false);
356 public static final TKeypress kbShiftEnter = new TKeypress(true,
357 TKeypress.ENTER, ' ', false, false, true);
358 public static final TKeypress kbShiftTab = new TKeypress(true,
359 TKeypress.TAB, ' ', false, false, true);
360 public static final TKeypress kbBackTab = new TKeypress(true,
361 TKeypress.BTAB, ' ', false, false, false);
362 public static final TKeypress kbShiftEsc = new TKeypress(true,
363 TKeypress.ESC, ' ', false, false, true);
364 public static final TKeypress kbShiftHome = new TKeypress(true,
365 TKeypress.HOME, ' ', false, false, true);
366 public static final TKeypress kbShiftEnd = new TKeypress(true,
367 TKeypress.END, ' ', false, false, true);
368 public static final TKeypress kbShiftPgUp = new TKeypress(true,
369 TKeypress.PGUP, ' ', false, false, true);
370 public static final TKeypress kbShiftPgDn = new TKeypress(true,
371 TKeypress.PGDN, ' ', false, false, true);
372 public static final TKeypress kbShiftIns = new TKeypress(true,
373 TKeypress.INS, ' ', false, false, true);
374 public static final TKeypress kbShiftDel = new TKeypress(true,
375 TKeypress.DEL, ' ', false, false, true);
376 public static final TKeypress kbShiftUp = new TKeypress(true,
377 TKeypress.UP, ' ', false, false, true);
378 public static final TKeypress kbShiftDown = new TKeypress(true,
379 TKeypress.DOWN, ' ', false, false, true);
380 public static final TKeypress kbShiftLeft = new TKeypress(true,
381 TKeypress.LEFT, ' ', false, false, true);
382 public static final TKeypress kbShiftRight = new TKeypress(true,
383 TKeypress.RIGHT, ' ', false, false, true);
384 public static final TKeypress kbA = new TKeypress(false,
385 0, 'a', false, false, false);
386 public static final TKeypress kbB = new TKeypress(false,
387 0, 'b', false, false, false);
388 public static final TKeypress kbC = new TKeypress(false,
389 0, 'c', false, false, false);
390 public static final TKeypress kbD = new TKeypress(false,
391 0, 'd', false, false, false);
392 public static final TKeypress kbE = new TKeypress(false,
393 0, 'e', false, false, false);
394 public static final TKeypress kbF = new TKeypress(false,
395 0, 'f', false, false, false);
396 public static final TKeypress kbG = new TKeypress(false,
397 0, 'g', false, false, false);
398 public static final TKeypress kbH = new TKeypress(false,
399 0, 'h', false, false, false);
400 public static final TKeypress kbI = new TKeypress(false,
401 0, 'i', false, false, false);
402 public static final TKeypress kbJ = new TKeypress(false,
403 0, 'j', false, false, false);
404 public static final TKeypress kbK = new TKeypress(false,
405 0, 'k', false, false, false);
406 public static final TKeypress kbL = new TKeypress(false,
407 0, 'l', false, false, false);
408 public static final TKeypress kbM = new TKeypress(false,
409 0, 'm', false, false, false);
410 public static final TKeypress kbN = new TKeypress(false,
411 0, 'n', false, false, false);
412 public static final TKeypress kbO = new TKeypress(false,
413 0, 'o', false, false, false);
414 public static final TKeypress kbP = new TKeypress(false,
415 0, 'p', false, false, false);
416 public static final TKeypress kbQ = new TKeypress(false,
417 0, 'q', false, false, false);
418 public static final TKeypress kbR = new TKeypress(false,
419 0, 'r', false, false, false);
420 public static final TKeypress kbS = new TKeypress(false,
421 0, 's', false, false, false);
422 public static final TKeypress kbT = new TKeypress(false,
423 0, 't', false, false, false);
424 public static final TKeypress kbU = new TKeypress(false,
425 0, 'u', false, false, false);
426 public static final TKeypress kbV = new TKeypress(false,
427 0, 'v', false, false, false);
428 public static final TKeypress kbW = new TKeypress(false,
429 0, 'w', false, false, false);
430 public static final TKeypress kbX = new TKeypress(false,
431 0, 'x', false, false, false);
432 public static final TKeypress kbY = new TKeypress(false,
433 0, 'y', false, false, false);
434 public static final TKeypress kbZ = new TKeypress(false,
435 0, 'z', false, false, false);
436 public static final TKeypress kbSpace = new TKeypress(false,
437 0, ' ', false, false, false);
438 public static final TKeypress kbAltA = new TKeypress(false,
439 0, 'a', true, false, false);
440 public static final TKeypress kbAltB = new TKeypress(false,
441 0, 'b', true, false, false);
442 public static final TKeypress kbAltC = new TKeypress(false,
443 0, 'c', true, false, false);
444 public static final TKeypress kbAltD = new TKeypress(false,
445 0, 'd', true, false, false);
446 public static final TKeypress kbAltE = new TKeypress(false,
447 0, 'e', true, false, false);
448 public static final TKeypress kbAltF = new TKeypress(false,
449 0, 'f', true, false, false);
450 public static final TKeypress kbAltG = new TKeypress(false,
451 0, 'g', true, false, false);
452 public static final TKeypress kbAltH = new TKeypress(false,
453 0, 'h', true, false, false);
454 public static final TKeypress kbAltI = new TKeypress(false,
455 0, 'i', true, false, false);
456 public static final TKeypress kbAltJ = new TKeypress(false,
457 0, 'j', true, false, false);
458 public static final TKeypress kbAltK = new TKeypress(false,
459 0, 'k', true, false, false);
460 public static final TKeypress kbAltL = new TKeypress(false,
461 0, 'l', true, false, false);
462 public static final TKeypress kbAltM = new TKeypress(false,
463 0, 'm', true, false, false);
464 public static final TKeypress kbAltN = new TKeypress(false,
465 0, 'n', true, false, false);
466 public static final TKeypress kbAltO = new TKeypress(false,
467 0, 'o', true, false, false);
468 public static final TKeypress kbAltP = new TKeypress(false,
469 0, 'p', true, false, false);
470 public static final TKeypress kbAltQ = new TKeypress(false,
471 0, 'q', true, false, false);
472 public static final TKeypress kbAltR = new TKeypress(false,
473 0, 'r', true, false, false);
474 public static final TKeypress kbAltS = new TKeypress(false,
475 0, 's', true, false, false);
476 public static final TKeypress kbAltT = new TKeypress(false,
477 0, 't', true, false, false);
478 public static final TKeypress kbAltU = new TKeypress(false,
479 0, 'u', true, false, false);
480 public static final TKeypress kbAltV = new TKeypress(false,
481 0, 'v', true, false, false);
482 public static final TKeypress kbAltW = new TKeypress(false,
483 0, 'w', true, false, false);
484 public static final TKeypress kbAltX = new TKeypress(false,
485 0, 'x', true, false, false);
486 public static final TKeypress kbAltY = new TKeypress(false,
487 0, 'y', true, false, false);
488 public static final TKeypress kbAltZ = new TKeypress(false,
489 0, 'z', true, false, false);
490 public static final TKeypress kbAlt0 = new TKeypress(false,
491 0, '0', true, false, false);
492 public static final TKeypress kbAlt1 = new TKeypress(false,
493 0, '1', true, false, false);
494 public static final TKeypress kbAlt2 = new TKeypress(false,
495 0, '2', true, false, false);
496 public static final TKeypress kbAlt3 = new TKeypress(false,
497 0, '3', true, false, false);
498 public static final TKeypress kbAlt4 = new TKeypress(false,
499 0, '4', true, false, false);
500 public static final TKeypress kbAlt5 = new TKeypress(false,
501 0, '5', true, false, false);
502 public static final TKeypress kbAlt6 = new TKeypress(false,
503 0, '6', true, false, false);
504 public static final TKeypress kbAlt7 = new TKeypress(false,
505 0, '7', true, false, false);
506 public static final TKeypress kbAlt8 = new TKeypress(false,
507 0, '8', true, false, false);
508 public static final TKeypress kbAlt9 = new TKeypress(false,
509 0, '9', true, false, false);
510 public static final TKeypress kbCtrlA = new TKeypress(false,
511 0, 'A', false, true, false);
512 public static final TKeypress kbCtrlB = new TKeypress(false,
513 0, 'B', false, true, false);
514 public static final TKeypress kbCtrlC = new TKeypress(false,
515 0, 'C', false, true, false);
516 public static final TKeypress kbCtrlD = new TKeypress(false,
517 0, 'D', false, true, false);
518 public static final TKeypress kbCtrlE = new TKeypress(false,
519 0, 'E', false, true, false);
520 public static final TKeypress kbCtrlF = new TKeypress(false,
521 0, 'F', false, true, false);
522 public static final TKeypress kbCtrlG = new TKeypress(false,
523 0, 'G', false, true, false);
524 public static final TKeypress kbCtrlH = new TKeypress(false,
525 0, 'H', false, true, false);
526 public static final TKeypress kbCtrlI = new TKeypress(false,
527 0, 'I', false, true, false);
528 public static final TKeypress kbCtrlJ = new TKeypress(false,
529 0, 'J', false, true, false);
530 public static final TKeypress kbCtrlK = new TKeypress(false,
531 0, 'K', false, true, false);
532 public static final TKeypress kbCtrlL = new TKeypress(false,
533 0, 'L', false, true, false);
534 public static final TKeypress kbCtrlM = new TKeypress(false,
535 0, 'M', false, true, false);
536 public static final TKeypress kbCtrlN = new TKeypress(false,
537 0, 'N', false, true, false);
538 public static final TKeypress kbCtrlO = new TKeypress(false,
539 0, 'O', false, true, false);
540 public static final TKeypress kbCtrlP = new TKeypress(false,
541 0, 'P', false, true, false);
542 public static final TKeypress kbCtrlQ = new TKeypress(false,
543 0, 'Q', false, true, false);
544 public static final TKeypress kbCtrlR = new TKeypress(false,
545 0, 'R', false, true, false);
546 public static final TKeypress kbCtrlS = new TKeypress(false,
547 0, 'S', false, true, false);
548 public static final TKeypress kbCtrlT = new TKeypress(false,
549 0, 'T', false, true, false);
550 public static final TKeypress kbCtrlU = new TKeypress(false,
551 0, 'U', false, true, false);
552 public static final TKeypress kbCtrlV = new TKeypress(false,
553 0, 'V', false, true, false);
554 public static final TKeypress kbCtrlW = new TKeypress(false,
555 0, 'W', false, true, false);
556 public static final TKeypress kbCtrlX = new TKeypress(false,
557 0, 'X', false, true, false);
558 public static final TKeypress kbCtrlY = new TKeypress(false,
559 0, 'Y', false, true, false);
560 public static final TKeypress kbCtrlZ = new TKeypress(false,
561 0, 'Z', false, true, false);
562 public static final TKeypress kbAltShiftA = new TKeypress(false,
563 0, 'A', true, false, true);
564 public static final TKeypress kbAltShiftB = new TKeypress(false,
565 0, 'B', true, false, true);
566 public static final TKeypress kbAltShiftC = new TKeypress(false,
567 0, 'C', true, false, true);
568 public static final TKeypress kbAltShiftD = new TKeypress(false,
569 0, 'D', true, false, true);
570 public static final TKeypress kbAltShiftE = new TKeypress(false,
571 0, 'E', true, false, true);
572 public static final TKeypress kbAltShiftF = new TKeypress(false,
573 0, 'F', true, false, true);
574 public static final TKeypress kbAltShiftG = new TKeypress(false,
575 0, 'G', true, false, true);
576 public static final TKeypress kbAltShiftH = new TKeypress(false,
577 0, 'H', true, false, true);
578 public static final TKeypress kbAltShiftI = new TKeypress(false,
579 0, 'I', true, false, true);
580 public static final TKeypress kbAltShiftJ = new TKeypress(false,
581 0, 'J', true, false, true);
582 public static final TKeypress kbAltShiftK = new TKeypress(false,
583 0, 'K', true, false, true);
584 public static final TKeypress kbAltShiftL = new TKeypress(false,
585 0, 'L', true, false, true);
586 public static final TKeypress kbAltShiftM = new TKeypress(false,
587 0, 'M', true, false, true);
588 public static final TKeypress kbAltShiftN = new TKeypress(false,
589 0, 'N', true, false, true);
590 public static final TKeypress kbAltShiftO = new TKeypress(false,
591 0, 'O', true, false, true);
592 public static final TKeypress kbAltShiftP = new TKeypress(false,
593 0, 'P', true, false, true);
594 public static final TKeypress kbAltShiftQ = new TKeypress(false,
595 0, 'Q', true, false, true);
596 public static final TKeypress kbAltShiftR = new TKeypress(false,
597 0, 'R', true, false, true);
598 public static final TKeypress kbAltShiftS = new TKeypress(false,
599 0, 'S', true, false, true);
600 public static final TKeypress kbAltShiftT = new TKeypress(false,
601 0, 'T', true, false, true);
602 public static final TKeypress kbAltShiftU = new TKeypress(false,
603 0, 'U', true, false, true);
604 public static final TKeypress kbAltShiftV = new TKeypress(false,
605 0, 'V', true, false, true);
606 public static final TKeypress kbAltShiftW = new TKeypress(false,
607 0, 'W', true, false, true);
608 public static final TKeypress kbAltShiftX = new TKeypress(false,
609 0, 'X', true, false, true);
610 public static final TKeypress kbAltShiftY = new TKeypress(false,
611 0, 'Y', true, false, true);
612 public static final TKeypress kbAltShiftZ = new TKeypress(false,
613 0, 'Z', true, false, true);
614
615 public static final TKeypress kbAltShiftHome = new TKeypress(true,
616 TKeypress.HOME, ' ', true, false, true);
617 public static final TKeypress kbAltShiftEnd = new TKeypress(true,
618 TKeypress.END, ' ', true, false, true);
619 public static final TKeypress kbAltShiftPgUp = new TKeypress(true,
620 TKeypress.PGUP, ' ', true, false, true);
621 public static final TKeypress kbAltShiftPgDn = new TKeypress(true,
622 TKeypress.PGDN, ' ', true, false, true);
623 public static final TKeypress kbAltShiftUp = new TKeypress(true,
624 TKeypress.UP, ' ', true, false, true);
625 public static final TKeypress kbAltShiftDown = new TKeypress(true,
626 TKeypress.DOWN, ' ', true, false, true);
627 public static final TKeypress kbAltShiftLeft = new TKeypress(true,
628 TKeypress.LEFT, ' ', true, false, true);
629 public static final TKeypress kbAltShiftRight = new TKeypress(true,
630 TKeypress.RIGHT, ' ', true, false, true);
631
632 public static final TKeypress kbCtrlShiftHome = new TKeypress(true,
633 TKeypress.HOME, ' ', false, true, true);
634 public static final TKeypress kbCtrlShiftEnd = new TKeypress(true,
635 TKeypress.END, ' ', false, true, true);
636 public static final TKeypress kbCtrlShiftPgUp = new TKeypress(true,
637 TKeypress.PGUP, ' ', false, true, true);
638 public static final TKeypress kbCtrlShiftPgDn = new TKeypress(true,
639 TKeypress.PGDN, ' ', false, true, true);
640 public static final TKeypress kbCtrlShiftUp = new TKeypress(true,
641 TKeypress.UP, ' ', false, true, true);
642 public static final TKeypress kbCtrlShiftDown = new TKeypress(true,
643 TKeypress.DOWN, ' ', false, true, true);
644 public static final TKeypress kbCtrlShiftLeft = new TKeypress(true,
645 TKeypress.LEFT, ' ', false, true, true);
646 public static final TKeypress kbCtrlShiftRight = new TKeypress(true,
647 TKeypress.RIGHT, ' ', false, true, true);
648
649
650 /**
651 * Backspace as ^H.
652 */
653 public static final TKeypress kbBackspace = new TKeypress(false,
654 0, 'H', false, true, false);
655
656 /**
657 * Backspace as ^?.
658 */
659 public static final TKeypress kbBackspaceDel = new TKeypress(false,
660 0, (char) 0x7F, false, false, false);
661
662 // ------------------------------------------------------------------------
663 // Variables --------------------------------------------------------------
664 // ------------------------------------------------------------------------
665
666 /**
667 * If true, ch is meaningless, use keyCode instead.
668 */
669 private boolean isFunctionKey;
670
671 /**
672 * Will be set to F1, F2, HOME, END, etc. if isKey is true.
673 */
674 private int keyCode;
675
676 /**
677 * Keystroke modifier ALT.
678 */
679 private boolean alt;
680
681 /**
682 * Keystroke modifier CTRL.
683 */
684 private boolean ctrl;
685
686 /**
687 * Keystroke modifier SHIFT.
688 */
689 private boolean shift;
690
691 /**
692 * The character received.
693 */
694 private int ch;
695
696 // ------------------------------------------------------------------------
697 // Constructors -----------------------------------------------------------
698 // ------------------------------------------------------------------------
699
700 /**
701 * Public constructor makes an immutable instance.
702 *
703 * @param isKey is true, this is a function key
704 * @param fnKey the function key code (only valid if isKey is true)
705 * @param ch the character (only valid if fnKey is false)
706 * @param alt if true, ALT was pressed with this keystroke
707 * @param ctrl if true, CTRL was pressed with this keystroke
708 * @param shift if true, SHIFT was pressed with this keystroke
709 */
710 public TKeypress(final boolean isKey, final int fnKey, final int ch,
711 final boolean alt, final boolean ctrl, final boolean shift) {
712
713 this.isFunctionKey = isKey;
714 this.keyCode = fnKey;
715 this.ch = ch;
716 this.alt = alt;
717 this.ctrl = ctrl;
718 this.shift = shift;
719 }
720
721 // ------------------------------------------------------------------------
722 // TKeypress --------------------------------------------------------------
723 // ------------------------------------------------------------------------
724
725 /**
726 * Getter for isFunctionKey.
727 *
728 * @return if true, ch is meaningless, use keyCode instead
729 */
730 public boolean isFnKey() {
731 return isFunctionKey;
732 }
733
734 /**
735 * Getter for function key code.
736 *
737 * @return function key code int value (only valid is isKey is true)
738 */
739 public int getKeyCode() {
740 return keyCode;
741 }
742
743 /**
744 * Getter for ALT.
745 *
746 * @return alt value
747 */
748 public boolean isAlt() {
749 return alt;
750 }
751
752 /**
753 * Getter for CTRL.
754 *
755 * @return ctrl value
756 */
757 public boolean isCtrl() {
758 return ctrl;
759 }
760
761 /**
762 * Getter for SHIFT.
763 *
764 * @return shift value
765 */
766 public boolean isShift() {
767 return shift;
768 }
769
770 /**
771 * Getter for character.
772 *
773 * @return the character (only valid if isKey is false)
774 */
775 public int getChar() {
776 return ch;
777 }
778
779 /**
780 * Create a duplicate instance.
781 *
782 * @return duplicate intance
783 */
784 public TKeypress dup() {
785 TKeypress keypress = new TKeypress(isFunctionKey, keyCode, ch,
786 alt, ctrl, shift);
787 return keypress;
788 }
789
790 /**
791 * Comparison check. All fields must match to return true.
792 *
793 * @param rhs another TKeypress instance
794 * @return true if all fields are equal
795 */
796 @Override
797 public boolean equals(final Object rhs) {
798 if (!(rhs instanceof TKeypress)) {
799 return false;
800 }
801
802 TKeypress that = (TKeypress) rhs;
803 return ((isFunctionKey == that.isFunctionKey)
804 && (keyCode == that.keyCode)
805 && (ch == that.ch)
806 && (alt == that.alt)
807 && (ctrl == that.ctrl)
808 && (shift == that.shift));
809 }
810
811 /**
812 * Comparison check, omitting the ctrl/alt/shift flags.
813 *
814 * @param rhs another TKeypress instance
815 * @return true if all fields (except for ctrl/alt/shift) are equal
816 */
817 public boolean equalsWithoutModifiers(final Object rhs) {
818 if (!(rhs instanceof TKeypress)) {
819 return false;
820 }
821
822 TKeypress that = (TKeypress) rhs;
823 return ((isFunctionKey == that.isFunctionKey)
824 && (keyCode == that.keyCode)
825 && (ch == that.ch));
826 }
827
828 /**
829 * Hashcode uses all fields in equals().
830 *
831 * @return the hash
832 */
833 @Override
834 public int hashCode() {
835 int A = 13;
836 int B = 23;
837 int hash = A;
838 hash = (B * hash) + (isFunctionKey ? 1 : 0);
839 hash = (B * hash) + keyCode;
840 hash = (B * hash) + ch;
841 hash = (B * hash) + (alt ? 1 : 0);
842 hash = (B * hash) + (ctrl ? 1 : 0);
843 hash = (B * hash) + (shift ? 1 : 0);
844 return hash;
845 }
846
847 /**
848 * Make human-readable description of this TKeypress.
849 *
850 * @return displayable String
851 */
852 @Override
853 public String toString() {
854 // Special case: Enter is "<arrow> <line> <angle>"
855 if (equals(kbEnter)) {
856 return "\u25C0\u2500\u2518";
857 }
858
859 // Special case: Space is "Space"
860 if (equals(kbSpace)) {
861 return "Space";
862 }
863
864 if (equals(kbShiftLeft)) {
865 return "Shift+\u2190";
866 }
867 if (equals(kbShiftRight)) {
868 return "Shift+\u2192";
869 }
870
871 if (isFunctionKey) {
872 switch (keyCode) {
873 case F1:
874 return String.format("%s%s%sF1",
875 ctrl ? "Ctrl+" : "",
876 alt ? "Alt+" : "",
877 shift ? "Shift+" : "");
878 case F2:
879 return String.format("%s%s%sF2",
880 ctrl ? "Ctrl+" : "",
881 alt ? "Alt+" : "",
882 shift ? "Shift+" : "");
883 case F3:
884 return String.format("%s%s%sF3",
885 ctrl ? "Ctrl+" : "",
886 alt ? "Alt+" : "",
887 shift ? "Shift+" : "");
888 case F4:
889 return String.format("%s%s%sF4",
890 ctrl ? "Ctrl+" : "",
891 alt ? "Alt+" : "",
892 shift ? "Shift+" : "");
893 case F5:
894 return String.format("%s%s%sF5",
895 ctrl ? "Ctrl+" : "",
896 alt ? "Alt+" : "",
897 shift ? "Shift+" : "");
898 case F6:
899 return String.format("%s%s%sF6",
900 ctrl ? "Ctrl+" : "",
901 alt ? "Alt+" : "",
902 shift ? "Shift+" : "");
903 case F7:
904 return String.format("%s%s%sF7",
905 ctrl ? "Ctrl+" : "",
906 alt ? "Alt+" : "",
907 shift ? "Shift+" : "");
908 case F8:
909 return String.format("%s%s%sF8",
910 ctrl ? "Ctrl+" : "",
911 alt ? "Alt+" : "",
912 shift ? "Shift+" : "");
913 case F9:
914 return String.format("%s%s%sF9",
915 ctrl ? "Ctrl+" : "",
916 alt ? "Alt+" : "",
917 shift ? "Shift+" : "");
918 case F10:
919 return String.format("%s%s%sF10",
920 ctrl ? "Ctrl+" : "",
921 alt ? "Alt+" : "",
922 shift ? "Shift+" : "");
923 case F11:
924 return String.format("%s%s%sF11",
925 ctrl ? "Ctrl+" : "",
926 alt ? "Alt+" : "",
927 shift ? "Shift+" : "");
928 case F12:
929 return String.format("%s%s%sF12",
930 ctrl ? "Ctrl+" : "",
931 alt ? "Alt+" : "",
932 shift ? "Shift+" : "");
933 case HOME:
934 return String.format("%s%s%sHOME",
935 ctrl ? "Ctrl+" : "",
936 alt ? "Alt+" : "",
937 shift ? "Shift+" : "");
938 case END:
939 return String.format("%s%s%sEND",
940 ctrl ? "Ctrl+" : "",
941 alt ? "Alt+" : "",
942 shift ? "Shift+" : "");
943 case PGUP:
944 return String.format("%s%s%sPGUP",
945 ctrl ? "Ctrl+" : "",
946 alt ? "Alt+" : "",
947 shift ? "Shift+" : "");
948 case PGDN:
949 return String.format("%s%s%sPGDN",
950 ctrl ? "Ctrl+" : "",
951 alt ? "Alt+" : "",
952 shift ? "Shift+" : "");
953 case INS:
954 return String.format("%s%s%sINS",
955 ctrl ? "Ctrl+" : "",
956 alt ? "Alt+" : "",
957 shift ? "Shift+" : "");
958 case DEL:
959 return String.format("%s%s%sDEL",
960 ctrl ? "Ctrl+" : "",
961 alt ? "Alt+" : "",
962 shift ? "Shift+" : "");
963 case RIGHT:
964 return String.format("%s%s%sRIGHT",
965 ctrl ? "Ctrl+" : "",
966 alt ? "Alt+" : "",
967 shift ? "Shift+" : "");
968 case LEFT:
969 return String.format("%s%s%sLEFT",
970 ctrl ? "Ctrl+" : "",
971 alt ? "Alt+" : "",
972 shift ? "Shift+" : "");
973 case UP:
974 return String.format("%s%s%sUP",
975 ctrl ? "Ctrl+" : "",
976 alt ? "Alt+" : "",
977 shift ? "Shift+" : "");
978 case DOWN:
979 return String.format("%s%s%sDOWN",
980 ctrl ? "Ctrl+" : "",
981 alt ? "Alt+" : "",
982 shift ? "Shift+" : "");
983 case TAB:
984 return String.format("%s%s%sTAB",
985 ctrl ? "Ctrl+" : "",
986 alt ? "Alt+" : "",
987 shift ? "Shift+" : "");
988 case BTAB:
989 return String.format("%s%s%sBTAB",
990 ctrl ? "Ctrl+" : "",
991 alt ? "Alt+" : "",
992 shift ? "Shift+" : "");
993 case ENTER:
994 return String.format("%s%s%sENTER",
995 ctrl ? "Ctrl+" : "",
996 alt ? "Alt+" : "",
997 shift ? "Shift+" : "");
998 case ESC:
999 return String.format("%s%s%sESC",
1000 ctrl ? "Ctrl+" : "",
1001 alt ? "Alt+" : "",
1002 shift ? "Shift+" : "");
1003 default:
1004 return String.format("--UNKNOWN--");
1005 }
1006 } else {
1007 if (alt && !shift && !ctrl) {
1008 // Alt-X
1009 return String.format("Alt+%c", Character.toUpperCase(ch));
1010 } else if (!alt && shift && !ctrl) {
1011 // Shift-X
1012 return String.format("%c", ch);
1013 } else if (!alt && !shift && ctrl) {
1014 // Ctrl-X
1015 return String.format("Ctrl+%c", ch);
1016 } else if (alt && shift && !ctrl) {
1017 // Alt-Shift-X
1018 return String.format("Alt+Shift+%c", ch);
1019 } else if (!alt && shift && ctrl) {
1020 // Ctrl-Shift-X
1021 return String.format("Ctrl+Shift+%c", ch);
1022 } else if (alt && !shift && ctrl) {
1023 // Ctrl-Alt-X
1024 return String.format("Ctrl+Alt+%c", Character.toUpperCase(ch));
1025 } else if (alt && shift && ctrl) {
1026 // Ctrl-Alt-Shift-X
1027 return String.format("Ctrl+Alt+Shift+%c",
1028 Character.toUpperCase(ch));
1029 } else {
1030 // X
1031 return String.format("%c", ch);
1032 }
1033 }
1034 }
1035
1036 /**
1037 * Convert a keypress to lowercase. Function keys and alt/ctrl keys are
1038 * not converted.
1039 *
1040 * @return a new instance with the key converted
1041 */
1042 public TKeypress toLowerCase() {
1043 TKeypress newKey = new TKeypress(isFunctionKey, keyCode, ch, alt, ctrl,
1044 shift);
1045 if (!isFunctionKey && (ch >= 'A') && (ch <= 'Z') && !ctrl && !alt) {
1046 newKey.shift = false;
1047 newKey.ch += 32;
1048 }
1049 return newKey;
1050 }
1051
1052 /**
1053 * Convert a keypress to uppercase. Function keys and alt/ctrl keys are
1054 * not converted.
1055 *
1056 * @return a new instance with the key converted
1057 */
1058 public TKeypress toUpperCase() {
1059 TKeypress newKey = new TKeypress(isFunctionKey, keyCode, ch, alt, ctrl,
1060 shift);
1061 if (!isFunctionKey && (ch >= 'a') && (ch <= 'z') && !ctrl && !alt) {
1062 newKey.shift = true;
1063 newKey.ch -= 32;
1064 }
1065 return newKey;
1066 }
1067
1068 }