Class KeyStroke

java.lang.Object
org.eclipse.ui.keys.KeyStroke
All Implemented Interfaces:
Comparable

@Deprecated(forRemoval=true, since="2024-03") public final class KeyStroke extends Object implements Comparable
Deprecated, for removal: This API element is subject to removal in a future version.
Please use org.eclipse.jface.bindings.keys.KeyStroke

A KeyStroke is defined as an optional set of modifier keys followed optionally by a natural key. A KeyStroke is said to be complete if it contains a natural key. A natural key is any Unicode character (e.g., "backspace", etc.), any character belonging to a natural language (e.g., "A", "1", "[", etc.), or any special control character specific to computers (e.g., "F10", "PageUp", etc.).

All KeyStroke objects have a formal string representation available via the toString() method. There are a number of methods to get instances of KeyStroke objects, including one which can parse this formal string representation.

All KeyStroke objects, via the format() method, provide a version of their formal string representation translated by platform and locale, suitable for display to a user.

KeyStroke objects are immutable. Clients are not permitted to extend this class.

Since:
3.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    The delimiter between multiple keys in a single key strokes -- expressed in the formal key stroke grammar.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    The set of delimiters for Key objects allowed during parsing of the formal string representation.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(Object object)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    boolean
    equals(Object object)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
    Formats this key stroke into the current default look.
    static KeyStroke
    Deprecated, for removal: This API element is subject to removal in a future version.
    Gets an instance of KeyStroke by parsing a given a formal string representation.
    static KeyStroke
    getInstance(SortedSet modifierKeys, NaturalKey naturalKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Gets an instance of KeyStroke given a set of modifier keys and a natural key.
    static KeyStroke
    getInstance(ModifierKey[] modifierKeys, NaturalKey naturalKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Gets an instance of KeyStroke given an array of modifier keys and a natural key.
    static KeyStroke
    getInstance(ModifierKey modifierKey, NaturalKey naturalKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Gets an instance of KeyStroke given a single modifier key and a natural key.
    static KeyStroke
    getInstance(NaturalKey naturalKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Gets an instance of KeyStroke given a natural key.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns the set of modifier keys for this key stroke.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns the natural key for this key stroke.
    int
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns whether or not this key stroke is complete.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns the formal string representation for this key stroke.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • KEY_DELIMITER

      public static final String KEY_DELIMITER
      Deprecated, for removal: This API element is subject to removal in a future version.
      The delimiter between multiple keys in a single key strokes -- expressed in the formal key stroke grammar. This is not to be displayed to the user. It is only intended as an internal representation.
      See Also:
    • KEY_DELIMITERS

      public static final String KEY_DELIMITERS
      Deprecated, for removal: This API element is subject to removal in a future version.
      The set of delimiters for Key objects allowed during parsing of the formal string representation.
      See Also:
  • Method Details

    • getInstance

      public static KeyStroke getInstance(ModifierKey modifierKey, NaturalKey naturalKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets an instance of KeyStroke given a single modifier key and a natural key.
      Parameters:
      modifierKey - a modifier key. Must not be null.
      naturalKey - the natural key. May be null.
      Returns:
      a key stroke. Guaranteed not to be null.
    • getInstance

      public static KeyStroke getInstance(ModifierKey[] modifierKeys, NaturalKey naturalKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets an instance of KeyStroke given an array of modifier keys and a natural key.
      Parameters:
      modifierKeys - the array of modifier keys. This array may be empty, but it must not be null. If this array is not empty, it must not contain null elements.
      naturalKey - the natural key. May be null.
      Returns:
      a key stroke. Guaranteed not to be null.
    • getInstance

      public static KeyStroke getInstance(NaturalKey naturalKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets an instance of KeyStroke given a natural key.
      Parameters:
      naturalKey - the natural key. May be null.
      Returns:
      a key stroke. This key stroke will have no modifier keys. Guaranteed not to be null.
    • getInstance

      public static KeyStroke getInstance(SortedSet modifierKeys, NaturalKey naturalKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets an instance of KeyStroke given a set of modifier keys and a natural key.
      Parameters:
      modifierKeys - the set of modifier keys. This set may be empty, but it must not be null. If this set is not empty, it must only contain instances of ModifierKey.
      naturalKey - the natural key. May be null.
      Returns:
      a key stroke. Guaranteed not to be null.
    • getInstance

      public static KeyStroke getInstance(String string) throws ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets an instance of KeyStroke by parsing a given a formal string representation.
      Parameters:
      string - the formal string representation to parse.
      Returns:
      a key stroke. Guaranteed not to be null.
      Throws:
      ParseException - if the given formal string representation could not be parsed to a valid key stroke.
    • compareTo

      public int compareTo(Object object)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      compareTo in interface Comparable
      See Also:
    • equals

      public boolean equals(Object object)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Overrides:
      equals in class Object
    • format

      public String format()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Formats this key stroke into the current default look.
      Returns:
      A string representation for this key stroke using the default look; never null.
    • getModifierKeys

      public Set getModifierKeys()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the set of modifier keys for this key stroke.
      Returns:
      the set of modifier keys. This set may be empty, but is guaranteed not to be null. If this set is not empty, it is guaranteed to only contain instances of ModifierKey.
    • getNaturalKey

      public NaturalKey getNaturalKey()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the natural key for this key stroke.
      Returns:
      the natural key. May be null.
    • hashCode

      public int hashCode()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Overrides:
      hashCode in class Object
    • isComplete

      public boolean isComplete()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns whether or not this key stroke is complete. Key strokes are complete iff they have a natural key which is not null.
      Returns:
      true, iff the key stroke is complete.
    • toString

      public String toString()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the formal string representation for this key stroke.
      Overrides:
      toString in class Object
      Returns:
      The formal string representation for this key stroke. Guaranteed not to be null.