Class KeyboardEvent

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
KeyDownEvent, KeyPressEvent, KeyUpEvent

public abstract class KeyboardEvent extends ComponentEvent<Component>
Abstract class for keyboard events.
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • KeyboardEvent

      public KeyboardEvent(Component source, boolean fromClient, String key, String code, int location, boolean ctrlKey, boolean shiftKey, boolean altKey, boolean metaKey, boolean repeat, boolean composing)
      Creates a new keyboard event.
      Parameters:
      source - the component that fired the event
      fromClient - true if the event was originally fired on the client, false if the event originates from server-side logic
      key - the string value representing the key
      code - the string value representing the code (nullable)
      location - the integer value representing the location of the key
      ctrlKey - true if the control key was down when the event was fired, false otherwise
      shiftKey - true if the shift key was down when the event was fired, false otherwise
      altKey - true if the alt key was down when the event was fired, false otherwise
      metaKey - true if the meta key was down when the event was fired, false otherwise
      repeat - true if the key has been pressed in a sustained manner
      composing - true if the key event occurred as part of a composition session
    • KeyboardEvent

      public KeyboardEvent(Component source, String key)
      Creates a new server-side keyboard event with no additional information.
      Parameters:
      source - the component that fired the event
      key - the key for this event
    • KeyboardEvent

      public KeyboardEvent(Component source, String key, String code)
      Creates a new server-side keyboard event with no additional information.
      Parameters:
      source - the component that fired the event
      key - the key for this event
      code - the code for this event
  • Method Details

    • getKey

      public Key getKey()
      Gets the key of the event.
      Returns:
      the Key of the event
    • getCode

      public Optional<Key> getCode()
      Gets the code of the event. If the event did not contain a valid code, an empty Optional will be given.
      Returns:
      the optional code of the event as a Key
    • getLocation

      public KeyLocation getLocation()
      Gets the KeyLocation of the event.
      Returns:
      the KeyLocation of the event
    • isRepeat

      public boolean isRepeat()
      Checks whether the key has been pressed in a sustained manner.
      Returns:
      true if the key has been pressed in a sustained manner
    • isComposing

      public boolean isComposing()
      Checks whether the key event occurred as part of a composition session.
      Returns:
      true if the key event occurred as part of a composition session
    • getModifiers

      public Set<KeyModifier> getModifiers()
      Gets the set of KeyModifier of the event.
      Returns:
      the set of KeyModifier