Update main screenshot
[nikiroo-utils.git] / src / jexer / TKeypress.java
... / ...
CommitLineData
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 */
29package jexer;
30
31/**
32 * This class represents keystrokes.
33 */
34public 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 /**
616 * Backspace as ^H.
617 */
618 public static final TKeypress kbBackspace = new TKeypress(false,
619 0, 'H', false, true, false);
620
621 /**
622 * Backspace as ^?.
623 */
624 public static final TKeypress kbBackspaceDel = new TKeypress(false,
625 0, (char) 0x7F, false, false, false);
626
627 // ------------------------------------------------------------------------
628 // Variables --------------------------------------------------------------
629 // ------------------------------------------------------------------------
630
631 /**
632 * If true, ch is meaningless, use keyCode instead.
633 */
634 private boolean isFunctionKey;
635
636 /**
637 * Will be set to F1, F2, HOME, END, etc. if isKey is true.
638 */
639 private int keyCode;
640
641 /**
642 * Keystroke modifier ALT.
643 */
644 private boolean alt;
645
646 /**
647 * Keystroke modifier CTRL.
648 */
649 private boolean ctrl;
650
651 /**
652 * Keystroke modifier SHIFT.
653 */
654 private boolean shift;
655
656 /**
657 * The character received.
658 */
659 private int ch;
660
661 // ------------------------------------------------------------------------
662 // Constructors -----------------------------------------------------------
663 // ------------------------------------------------------------------------
664
665 /**
666 * Public constructor makes an immutable instance.
667 *
668 * @param isKey is true, this is a function key
669 * @param fnKey the function key code (only valid if isKey is true)
670 * @param ch the character (only valid if fnKey is false)
671 * @param alt if true, ALT was pressed with this keystroke
672 * @param ctrl if true, CTRL was pressed with this keystroke
673 * @param shift if true, SHIFT was pressed with this keystroke
674 */
675 public TKeypress(final boolean isKey, final int fnKey, final int ch,
676 final boolean alt, final boolean ctrl, final boolean shift) {
677
678 this.isFunctionKey = isKey;
679 this.keyCode = fnKey;
680 this.ch = ch;
681 this.alt = alt;
682 this.ctrl = ctrl;
683 this.shift = shift;
684 }
685
686 // ------------------------------------------------------------------------
687 // TKeypress --------------------------------------------------------------
688 // ------------------------------------------------------------------------
689
690 /**
691 * Getter for isFunctionKey.
692 *
693 * @return if true, ch is meaningless, use keyCode instead
694 */
695 public boolean isFnKey() {
696 return isFunctionKey;
697 }
698
699 /**
700 * Getter for function key code.
701 *
702 * @return function key code int value (only valid is isKey is true)
703 */
704 public int getKeyCode() {
705 return keyCode;
706 }
707
708 /**
709 * Getter for ALT.
710 *
711 * @return alt value
712 */
713 public boolean isAlt() {
714 return alt;
715 }
716
717 /**
718 * Getter for CTRL.
719 *
720 * @return ctrl value
721 */
722 public boolean isCtrl() {
723 return ctrl;
724 }
725
726 /**
727 * Getter for SHIFT.
728 *
729 * @return shift value
730 */
731 public boolean isShift() {
732 return shift;
733 }
734
735 /**
736 * Getter for character.
737 *
738 * @return the character (only valid if isKey is false)
739 */
740 public int getChar() {
741 return ch;
742 }
743
744 /**
745 * Create a duplicate instance.
746 *
747 * @return duplicate intance
748 */
749 public TKeypress dup() {
750 TKeypress keypress = new TKeypress(isFunctionKey, keyCode, ch,
751 alt, ctrl, shift);
752 return keypress;
753 }
754
755 /**
756 * Comparison check. All fields must match to return true.
757 *
758 * @param rhs another TKeypress instance
759 * @return true if all fields are equal
760 */
761 @Override
762 public boolean equals(final Object rhs) {
763 if (!(rhs instanceof TKeypress)) {
764 return false;
765 }
766
767 TKeypress that = (TKeypress) rhs;
768 return ((isFunctionKey == that.isFunctionKey)
769 && (keyCode == that.keyCode)
770 && (ch == that.ch)
771 && (alt == that.alt)
772 && (ctrl == that.ctrl)
773 && (shift == that.shift));
774 }
775
776 /**
777 * Comparison check, omitting the ctrl/alt/shift flags.
778 *
779 * @param rhs another TKeypress instance
780 * @return true if all fields (except for ctrl/alt/shift) are equal
781 */
782 public boolean equalsWithoutModifiers(final Object rhs) {
783 if (!(rhs instanceof TKeypress)) {
784 return false;
785 }
786
787 TKeypress that = (TKeypress) rhs;
788 return ((isFunctionKey == that.isFunctionKey)
789 && (keyCode == that.keyCode)
790 && (ch == that.ch));
791 }
792
793 /**
794 * Hashcode uses all fields in equals().
795 *
796 * @return the hash
797 */
798 @Override
799 public int hashCode() {
800 int A = 13;
801 int B = 23;
802 int hash = A;
803 hash = (B * hash) + (isFunctionKey ? 1 : 0);
804 hash = (B * hash) + keyCode;
805 hash = (B * hash) + ch;
806 hash = (B * hash) + (alt ? 1 : 0);
807 hash = (B * hash) + (ctrl ? 1 : 0);
808 hash = (B * hash) + (shift ? 1 : 0);
809 return hash;
810 }
811
812 /**
813 * Make human-readable description of this TKeypress.
814 *
815 * @return displayable String
816 */
817 @Override
818 public String toString() {
819 // Special case: Enter is "<arrow> <line> <angle>"
820 if (equals(kbEnter)) {
821 return "\u25C0\u2500\u2518";
822 }
823
824 if (equals(kbShiftLeft)) {
825 return "Shift+\u2190";
826 }
827 if (equals(kbShiftRight)) {
828 return "Shift+\u2192";
829 }
830
831 if (isFunctionKey) {
832 switch (keyCode) {
833 case F1:
834 return String.format("%s%s%sF1",
835 ctrl ? "Ctrl+" : "",
836 alt ? "Alt+" : "",
837 shift ? "Shift+" : "");
838 case F2:
839 return String.format("%s%s%sF2",
840 ctrl ? "Ctrl+" : "",
841 alt ? "Alt+" : "",
842 shift ? "Shift+" : "");
843 case F3:
844 return String.format("%s%s%sF3",
845 ctrl ? "Ctrl+" : "",
846 alt ? "Alt+" : "",
847 shift ? "Shift+" : "");
848 case F4:
849 return String.format("%s%s%sF4",
850 ctrl ? "Ctrl+" : "",
851 alt ? "Alt+" : "",
852 shift ? "Shift+" : "");
853 case F5:
854 return String.format("%s%s%sF5",
855 ctrl ? "Ctrl+" : "",
856 alt ? "Alt+" : "",
857 shift ? "Shift+" : "");
858 case F6:
859 return String.format("%s%s%sF6",
860 ctrl ? "Ctrl+" : "",
861 alt ? "Alt+" : "",
862 shift ? "Shift+" : "");
863 case F7:
864 return String.format("%s%s%sF7",
865 ctrl ? "Ctrl+" : "",
866 alt ? "Alt+" : "",
867 shift ? "Shift+" : "");
868 case F8:
869 return String.format("%s%s%sF8",
870 ctrl ? "Ctrl+" : "",
871 alt ? "Alt+" : "",
872 shift ? "Shift+" : "");
873 case F9:
874 return String.format("%s%s%sF9",
875 ctrl ? "Ctrl+" : "",
876 alt ? "Alt+" : "",
877 shift ? "Shift+" : "");
878 case F10:
879 return String.format("%s%s%sF10",
880 ctrl ? "Ctrl+" : "",
881 alt ? "Alt+" : "",
882 shift ? "Shift+" : "");
883 case F11:
884 return String.format("%s%s%sF11",
885 ctrl ? "Ctrl+" : "",
886 alt ? "Alt+" : "",
887 shift ? "Shift+" : "");
888 case F12:
889 return String.format("%s%s%sF12",
890 ctrl ? "Ctrl+" : "",
891 alt ? "Alt+" : "",
892 shift ? "Shift+" : "");
893 case HOME:
894 return String.format("%s%s%sHOME",
895 ctrl ? "Ctrl+" : "",
896 alt ? "Alt+" : "",
897 shift ? "Shift+" : "");
898 case END:
899 return String.format("%s%s%sEND",
900 ctrl ? "Ctrl+" : "",
901 alt ? "Alt+" : "",
902 shift ? "Shift+" : "");
903 case PGUP:
904 return String.format("%s%s%sPGUP",
905 ctrl ? "Ctrl+" : "",
906 alt ? "Alt+" : "",
907 shift ? "Shift+" : "");
908 case PGDN:
909 return String.format("%s%s%sPGDN",
910 ctrl ? "Ctrl+" : "",
911 alt ? "Alt+" : "",
912 shift ? "Shift+" : "");
913 case INS:
914 return String.format("%s%s%sINS",
915 ctrl ? "Ctrl+" : "",
916 alt ? "Alt+" : "",
917 shift ? "Shift+" : "");
918 case DEL:
919 return String.format("%s%s%sDEL",
920 ctrl ? "Ctrl+" : "",
921 alt ? "Alt+" : "",
922 shift ? "Shift+" : "");
923 case RIGHT:
924 return String.format("%s%s%sRIGHT",
925 ctrl ? "Ctrl+" : "",
926 alt ? "Alt+" : "",
927 shift ? "Shift+" : "");
928 case LEFT:
929 return String.format("%s%s%sLEFT",
930 ctrl ? "Ctrl+" : "",
931 alt ? "Alt+" : "",
932 shift ? "Shift+" : "");
933 case UP:
934 return String.format("%s%s%sUP",
935 ctrl ? "Ctrl+" : "",
936 alt ? "Alt+" : "",
937 shift ? "Shift+" : "");
938 case DOWN:
939 return String.format("%s%s%sDOWN",
940 ctrl ? "Ctrl+" : "",
941 alt ? "Alt+" : "",
942 shift ? "Shift+" : "");
943 case TAB:
944 return String.format("%s%s%sTAB",
945 ctrl ? "Ctrl+" : "",
946 alt ? "Alt+" : "",
947 shift ? "Shift+" : "");
948 case BTAB:
949 return String.format("%s%s%sBTAB",
950 ctrl ? "Ctrl+" : "",
951 alt ? "Alt+" : "",
952 shift ? "Shift+" : "");
953 case ENTER:
954 return String.format("%s%s%sENTER",
955 ctrl ? "Ctrl+" : "",
956 alt ? "Alt+" : "",
957 shift ? "Shift+" : "");
958 case ESC:
959 return String.format("%s%s%sESC",
960 ctrl ? "Ctrl+" : "",
961 alt ? "Alt+" : "",
962 shift ? "Shift+" : "");
963 default:
964 return String.format("--UNKNOWN--");
965 }
966 } else {
967 if (alt && !shift && !ctrl) {
968 // Alt-X
969 return String.format("Alt+%c", Character.toUpperCase(ch));
970 } else if (!alt && shift && !ctrl) {
971 // Shift-X
972 return String.format("%c", ch);
973 } else if (!alt && !shift && ctrl) {
974 // Ctrl-X
975 return String.format("Ctrl+%c", ch);
976 } else if (alt && shift && !ctrl) {
977 // Alt-Shift-X
978 return String.format("Alt+Shift+%c", ch);
979 } else if (!alt && shift && ctrl) {
980 // Ctrl-Shift-X
981 return String.format("Ctrl+Shift+%c", ch);
982 } else if (alt && !shift && ctrl) {
983 // Ctrl-Alt-X
984 return String.format("Ctrl+Alt+%c", Character.toUpperCase(ch));
985 } else if (alt && shift && ctrl) {
986 // Ctrl-Alt-Shift-X
987 return String.format("Ctrl+Alt+Shift+%c",
988 Character.toUpperCase(ch));
989 } else {
990 // X
991 return String.format("%c", ch);
992 }
993 }
994 }
995
996 /**
997 * Convert a keypress to lowercase. Function keys and alt/ctrl keys are
998 * not converted.
999 *
1000 * @return a new instance with the key converted
1001 */
1002 public TKeypress toLowerCase() {
1003 TKeypress newKey = new TKeypress(isFunctionKey, keyCode, ch, alt, ctrl,
1004 shift);
1005 if (!isFunctionKey && (ch >= 'A') && (ch <= 'Z') && !ctrl && !alt) {
1006 newKey.shift = false;
1007 newKey.ch += 32;
1008 }
1009 return newKey;
1010 }
1011
1012 /**
1013 * Convert a keypress to uppercase. Function keys and alt/ctrl keys are
1014 * not converted.
1015 *
1016 * @return a new instance with the key converted
1017 */
1018 public TKeypress toUpperCase() {
1019 TKeypress newKey = new TKeypress(isFunctionKey, keyCode, ch, alt, ctrl,
1020 shift);
1021 if (!isFunctionKey && (ch >= 'a') && (ch <= 'z') && !ctrl && !alt) {
1022 newKey.shift = true;
1023 newKey.ch -= 32;
1024 }
1025 return newKey;
1026 }
1027
1028}