/Users/lyon/j4p/src/gui/keyboard/KeyController.java
|
1 package gui.keyboard;
2
3 import java.awt.event.KeyEvent;
4
5
6 final class KeyController implements
7 java.awt.event.KeyListener {
8 public void keyPressed(final java.awt.event.KeyEvent e) {
9 final char keyChar = e.getKeyChar();
10 final int keyCode = e.getKeyCode();
11 final String keyText = KeyEvent.getKeyText(keyCode);
12
13 final int modifiers = e.getModifiers();
14 final String modifierText = KeyEvent.getKeyModifiersText(modifiers);
15
16
17 System.out.println("keyChar=" + (int) keyChar);
18 System.out.println("keyText=" + keyText);
19 System.out.println("modifiers=" + modifiers);
20 System.out.println("modifierText=" + modifierText);
21
22 System.out.println("processModifiers=" + processModifiers(e));
23
24
25 }
26
27 private static String processModifiers(final java.awt.event.KeyEvent e) {
28 final int modifiers = e.getModifiers();
29 final int keyCode = e.getKeyCode();
30 final String keyText = KeyEvent.getKeyText(keyCode);
31
32 String s = "";
33 if ((modifiers & java.awt.event.InputEvent.META_MASK) != 0)
34 s = s + "M-";
35
36 if ((modifiers & java.awt.event.InputEvent.CTRL_MASK) != 0)
37 s = s + "^-";
38
39 if ((modifiers & java.awt.event.InputEvent.ALT_MASK) != 0)
40 s = s + "A-";
41
42 if ((modifiers & java.awt.event.InputEvent.SHIFT_MASK) != 0)
43 s = s + "Shift-";
44
45 return s + keyText;
46 }
47
48 public void keyTyped(final java.awt.event.KeyEvent e) {
49 System.out.println(e);
50 }
51
52 public void keyReleased(final java.awt.event.KeyEvent e) {
53 System.out.println(e);
54 }
55 }