2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
32 * This class represents keystrokes.
34 public class TKeypress
{
36 // ------------------------------------------------------------------------
37 // Constants --------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 // Various special keystrokes
45 public static final int NONE
= 255;
50 public static final int F1
= 1;
55 public static final int F2
= 2;
60 public static final int F3
= 3;
65 public static final int F4
= 4;
70 public static final int F5
= 5;
75 public static final int F6
= 6;
80 public static final int F7
= 7;
85 public static final int F8
= 8;
90 public static final int F9
= 9;
95 public static final int F10
= 10;
100 public static final int F11
= 11;
105 public static final int F12
= 12;
110 public static final int HOME
= 20;
115 public static final int END
= 21;
120 public static final int PGUP
= 22;
125 public static final int PGDN
= 23;
130 public static final int INS
= 24;
135 public static final int DEL
= 25;
140 public static final int RIGHT
= 30;
145 public static final int LEFT
= 31;
150 public static final int UP
= 32;
155 public static final int DOWN
= 33;
160 public static final int TAB
= 40;
163 * Back-tab (shift-tab).
165 public static final int BTAB
= 41;
170 public static final int ENTER
= 42;
175 public static final int ESC
= 43;
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);
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);
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);
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);
653 public static final TKeypress kbBackspace
= new TKeypress(false,
654 0, 'H', false, true, false);
659 public static final TKeypress kbBackspaceDel
= new TKeypress(false,
660 0, (char) 0x7F, false, false, false);
662 // ------------------------------------------------------------------------
663 // Variables --------------------------------------------------------------
664 // ------------------------------------------------------------------------
667 * If true, ch is meaningless, use keyCode instead.
669 private boolean isFunctionKey
;
672 * Will be set to F1, F2, HOME, END, etc. if isKey is true.
677 * Keystroke modifier ALT.
682 * Keystroke modifier CTRL.
684 private boolean ctrl
;
687 * Keystroke modifier SHIFT.
689 private boolean shift
;
692 * The character received.
696 // ------------------------------------------------------------------------
697 // Constructors -----------------------------------------------------------
698 // ------------------------------------------------------------------------
701 * Public constructor makes an immutable instance.
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
710 public TKeypress(final boolean isKey
, final int fnKey
, final int ch
,
711 final boolean alt
, final boolean ctrl
, final boolean shift
) {
713 this.isFunctionKey
= isKey
;
714 this.keyCode
= fnKey
;
721 // ------------------------------------------------------------------------
722 // TKeypress --------------------------------------------------------------
723 // ------------------------------------------------------------------------
726 * Getter for isFunctionKey.
728 * @return if true, ch is meaningless, use keyCode instead
730 public boolean isFnKey() {
731 return isFunctionKey
;
735 * Getter for function key code.
737 * @return function key code int value (only valid is isKey is true)
739 public int getKeyCode() {
748 public boolean isAlt() {
757 public boolean isCtrl() {
764 * @return shift value
766 public boolean isShift() {
771 * Getter for character.
773 * @return the character (only valid if isKey is false)
775 public int getChar() {
780 * Create a duplicate instance.
782 * @return duplicate intance
784 public TKeypress
dup() {
785 TKeypress keypress
= new TKeypress(isFunctionKey
, keyCode
, ch
,
791 * Comparison check. All fields must match to return true.
793 * @param rhs another TKeypress instance
794 * @return true if all fields are equal
797 public boolean equals(final Object rhs
) {
798 if (!(rhs
instanceof TKeypress
)) {
802 TKeypress that
= (TKeypress
) rhs
;
803 return ((isFunctionKey
== that
.isFunctionKey
)
804 && (keyCode
== that
.keyCode
)
807 && (ctrl
== that
.ctrl
)
808 && (shift
== that
.shift
));
812 * Comparison check, omitting the ctrl/alt/shift flags.
814 * @param rhs another TKeypress instance
815 * @return true if all fields (except for ctrl/alt/shift) are equal
817 public boolean equalsWithoutModifiers(final Object rhs
) {
818 if (!(rhs
instanceof TKeypress
)) {
822 TKeypress that
= (TKeypress
) rhs
;
823 return ((isFunctionKey
== that
.isFunctionKey
)
824 && (keyCode
== that
.keyCode
)
829 * Hashcode uses all fields in equals().
834 public int hashCode() {
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);
848 * Make human-readable description of this TKeypress.
850 * @return displayable String
853 public String
toString() {
854 // Special case: Enter is "<arrow> <line> <angle>"
855 if (equals(kbEnter
)) {
856 return "\u25C0\u2500\u2518";
859 // Special case: Space is "Space"
860 if (equals(kbSpace
)) {
864 if (equals(kbShiftLeft
)) {
865 return "Shift+\u2190";
867 if (equals(kbShiftRight
)) {
868 return "Shift+\u2192";
874 return String
.format("%s%s%sF1",
877 shift ?
"Shift+" : "");
879 return String
.format("%s%s%sF2",
882 shift ?
"Shift+" : "");
884 return String
.format("%s%s%sF3",
887 shift ?
"Shift+" : "");
889 return String
.format("%s%s%sF4",
892 shift ?
"Shift+" : "");
894 return String
.format("%s%s%sF5",
897 shift ?
"Shift+" : "");
899 return String
.format("%s%s%sF6",
902 shift ?
"Shift+" : "");
904 return String
.format("%s%s%sF7",
907 shift ?
"Shift+" : "");
909 return String
.format("%s%s%sF8",
912 shift ?
"Shift+" : "");
914 return String
.format("%s%s%sF9",
917 shift ?
"Shift+" : "");
919 return String
.format("%s%s%sF10",
922 shift ?
"Shift+" : "");
924 return String
.format("%s%s%sF11",
927 shift ?
"Shift+" : "");
929 return String
.format("%s%s%sF12",
932 shift ?
"Shift+" : "");
934 return String
.format("%s%s%sHOME",
937 shift ?
"Shift+" : "");
939 return String
.format("%s%s%sEND",
942 shift ?
"Shift+" : "");
944 return String
.format("%s%s%sPGUP",
947 shift ?
"Shift+" : "");
949 return String
.format("%s%s%sPGDN",
952 shift ?
"Shift+" : "");
954 return String
.format("%s%s%sINS",
957 shift ?
"Shift+" : "");
959 return String
.format("%s%s%sDEL",
962 shift ?
"Shift+" : "");
964 return String
.format("%s%s%sRIGHT",
967 shift ?
"Shift+" : "");
969 return String
.format("%s%s%sLEFT",
972 shift ?
"Shift+" : "");
974 return String
.format("%s%s%sUP",
977 shift ?
"Shift+" : "");
979 return String
.format("%s%s%sDOWN",
982 shift ?
"Shift+" : "");
984 return String
.format("%s%s%sTAB",
987 shift ?
"Shift+" : "");
989 return String
.format("%s%s%sBTAB",
992 shift ?
"Shift+" : "");
994 return String
.format("%s%s%sENTER",
997 shift ?
"Shift+" : "");
999 return String
.format("%s%s%sESC",
1000 ctrl ?
"Ctrl+" : "",
1002 shift ?
"Shift+" : "");
1004 return String
.format("--UNKNOWN--");
1007 if (alt
&& !shift
&& !ctrl
) {
1009 return String
.format("Alt+%c", Character
.toUpperCase(ch
));
1010 } else if (!alt
&& shift
&& !ctrl
) {
1012 return String
.format("%c", ch
);
1013 } else if (!alt
&& !shift
&& ctrl
) {
1015 return String
.format("Ctrl+%c", ch
);
1016 } else if (alt
&& shift
&& !ctrl
) {
1018 return String
.format("Alt+Shift+%c", ch
);
1019 } else if (!alt
&& shift
&& ctrl
) {
1021 return String
.format("Ctrl+Shift+%c", ch
);
1022 } else if (alt
&& !shift
&& ctrl
) {
1024 return String
.format("Ctrl+Alt+%c", Character
.toUpperCase(ch
));
1025 } else if (alt
&& shift
&& ctrl
) {
1027 return String
.format("Ctrl+Alt+Shift+%c",
1028 Character
.toUpperCase(ch
));
1031 return String
.format("%c", ch
);
1037 * Convert a keypress to lowercase. Function keys and alt/ctrl keys are
1040 * @return a new instance with the key converted
1042 public TKeypress
toLowerCase() {
1043 TKeypress newKey
= new TKeypress(isFunctionKey
, keyCode
, ch
, alt
, ctrl
,
1045 if (!isFunctionKey
&& (ch
>= 'A') && (ch
<= 'Z') && !ctrl
&& !alt
) {
1046 newKey
.shift
= false;
1053 * Convert a keypress to uppercase. Function keys and alt/ctrl keys are
1056 * @return a new instance with the key converted
1058 public TKeypress
toUpperCase() {
1059 TKeypress newKey
= new TKeypress(isFunctionKey
, keyCode
, ch
, alt
, ctrl
,
1061 if (!isFunctionKey
&& (ch
>= 'a') && (ch
<= 'z') && !ctrl
&& !alt
) {
1062 newKey
.shift
= true;