Listening to All Key Events Before Delivery to Focused Component : Key Event « Event « Java






Listening to All Key Events Before Delivery to Focused Component

    
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;

public class Main {
  public static void main(String[] argv) throws Exception {

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
        new KeyEventDispatcher() {
          public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_TYPED) {
              e.setKeyChar('a');
            }
            boolean discardEvent = false;
            return discardEvent;
          }
        });
  }
}

   
    
    
    
  








Related examples in the same category

1.KeyListener, ActionListener Demo 1KeyListener, ActionListener Demo 1
2.KeyListener, ActionListener Demo 2KeyListener, ActionListener Demo 2
3.Key event on frameKey event on frame
4.Responding to KeystrokesResponding to Keystrokes
5.Key Event DemoKey Event Demo
6.Set java.awt.Container.getFocusTraversalKeys(int id)
7.KeyStroke.getKeyStroke("F2")
8.Activating a Keystroke When Any Component in the Window Has Focus
9.InputMap javax.swing.JComponent.getInputMap(int condition)
10.Activating a Keystroke When Any Child Component Has Focus
11.List keystrokes in the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT input map of the component
12.List keystrokes in the WHEN_IN_FOCUSED_WINDOW input map of the component
13.Converting a KeyStroke to a String
14.Creating a KeyStroke and Binding It to an Action
15.void InputMap.put(KeyStroke keyStroke, Object actionMapKey)
16.Map actions with keystrokes
17.Handling Key Presses
18.Get key pressed as a key character (which is a Unicode character)
19.Get key pressed as a key code
20.Get Key Text
21.KeyStroke to String
22.Construct a new key description from a given universal string descriptionConstruct a new key description from a given universal string description
23.Reads for modifiers and creates integer with required mask