KeyEventTranslator (jEdit API Documentation)
Date: 2015-02-03

org.gjt.sp.jedit.gui

## Class KeyEventTranslator

- java.lang.Object
- - org.gjt.sp.jedit.gui.KeyEventTranslator

-     public class KeyEventTranslator
      extends java.lang.Object

  In conjunction with the `KeyEventWorkaround`, hides some warts in the AWT key event API.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `KeyEventTranslator.Key`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static boolean` | `lastKeyPressAccepted`
    `protected static java.awt.event.KeyEvent` | `lastKeyPressEvent`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `KeyEventTranslator()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addTranslation(KeyEventTranslator.Key key1, KeyEventTranslator.Key key2)` Adds a keyboard translation.
    `static java.lang.String` | `getModifierString(java.awt.event.InputEvent evt)` Returns a string containing symbolic modifier names set in the specified event.
    `static char` | `getSymbolicModifierName(int mod)` Returns a the symbolic modifier name for the specified Java modifier flag.
    `static java.lang.String` | `modifiersToString(int mods)`
    `static KeyEventTranslator.Key` | `parseKey(java.lang.String keyStroke)` Converts a string to a keystroke.
    `static javax.swing.KeyStroke` | `parseKeyStroke(java.lang.String shortcut)` Converts a string to a Swing KeyStroke.
    `static void` | `setModifierMapping(int c, int a, int m, int s)` Changes the mapping between symbolic modifier key names (`C`, `A`, `M`, `S`) and Java modifier flags.
    `static KeyEventTranslator.Key` | `translateKeyEvent(java.awt.event.KeyEvent evt)` Pass this an event from `KeyEventWorkaround.processKeyEvent(java.awt.event.KeyEvent)`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### lastKeyPressEvent

          protected static java.awt.event.KeyEvent lastKeyPressEvent

    - #### lastKeyPressAccepted

          protected static boolean lastKeyPressAccepted

  - ### Constructor Detail

    - #### KeyEventTranslator

          public KeyEventTranslator()

  - ### Method Detail

    - #### addTranslation

          public static void addTranslation(KeyEventTranslator.Key key1,
                            KeyEventTranslator.Key key2)

      Adds a keyboard translation.
      Parameters:
        `key1` - Translate this key
        `key2` - Into this key
      Since:
        jEdit 4.2pre3

    - #### translateKeyEvent

          public static KeyEventTranslator.Key translateKeyEvent(java.awt.event.KeyEvent evt)

      Pass this an event from `KeyEventWorkaround.processKeyEvent(java.awt.event.KeyEvent)`.
      Parameters:
        `evt` - the KeyEvent to translate
      Since:
        jEdit 4.2pre3

    - #### parseKey

          public static KeyEventTranslator.Key parseKey(java.lang.String keyStroke)

      Converts a string to a keystroke. The string should be of the form modifiers+shortcut where modifiers is any combination of A for Alt, C for Control, S for Shift or M for Meta, and shortcut is either a single character, or a keycode name from the `KeyEvent` class, without the `VK_` prefix.
      Parameters:
        `keyStroke` - A string description of the key stroke
      Since:
        jEdit 4.2pre3

    - #### parseKeyStroke

          public static javax.swing.KeyStroke parseKeyStroke(java.lang.String shortcut)

      Converts a string to a Swing KeyStroke. The string should be of the form modifiers+shortcut where modifiers is any combination of A for Alt, C for Control, S for Shift or M for Meta, and shortcut is either a single character, or a keycode name from the `KeyEvent` class, without the `VK_` prefix. Returns null if the string corresponds to multiple KeyStrokes (e.g., "C+e C+COMMA").
      Parameters:
        `shortcut` - A string description of the key stroke
      Since:
        jEdit 5.0

    - #### setModifierMapping

          public static void setModifierMapping(int c,
                                int a,
                                int m,
                                int s)

      Changes the mapping between symbolic modifier key names (`C`, `A`, `M`, `S`) and Java modifier flags. You can map more than one Java modifier to a symobolic modifier, for example :

      ``

                  setModifierMapping(
                          InputEvent.CTRL_MASK,
                          InputEvent.ALT_MASK | InputEvent.META_MASK,
                          0,
                          InputEvent.SHIFT_MASK);

           You cannot map a Java modifer to more than one symbolic modifier.

      Parameters:
        `c` - The modifier(s) to map the `C` modifier to
        `a` - The modifier(s) to map the `A` modifier to
        `m` - The modifier(s) to map the `M` modifier to
        `s` - The modifier(s) to map the `S` modifier to
      Since:
        jEdit 4.2pre3

    - #### getSymbolicModifierName

          public static char getSymbolicModifierName(int mod)

      Returns a the symbolic modifier name for the specified Java modifier flag.
      Parameters:
        `mod` - A modifier constant from `InputEvent`
      Since:
        jEdit 4.2pre3

    - #### modifiersToString

          public static java.lang.String modifiersToString(int mods)

    - #### getModifierString

          public static java.lang.String getModifierString(java.awt.event.InputEvent evt)

      Returns a string containing symbolic modifier names set in the specified event.
      Parameters:
        `evt` - The event
      Since:
        jEdit 4.2pre3