Class KeyboardEvent


public class KeyboardEvent extends BrowserEvent
This class contains the data about the keyboard events. These are the following:
  • The client on which the event occurred
  • The ID of the component on which the event occurred
  • The event type
  • The instance of the component, on which the event occurred
  • The event's unique ID
  • If the event is trusted
  • The amount of mouse clicks
  • The event phase
  • If the event is bubbleable
  • If the event can prevent the default operation
  • Marks if the event had defaultPrevented() called
  • If the event is composed or not
  • The ID of the client, on which the event occurred
  • If the ALT button was held down during the event
  • If the CONTROL button was held down during the event
  • If the Meta button was held down during the event
  • If the SHIFT button was held down during the event
  • The details of the pressed button (charCode, keyCode and the corresponding character)
  • The location (on the keyboard) of the pressed button
Since:
4.0
Author:
JBStrap
  • Constructor Details

    • KeyboardEvent

      public KeyboardEvent()
  • Method Details

    • getAltKey

      public Boolean getAltKey()
      Determines if the ALT key was held down when the event occurred
      Returns:
      true, if the ALT button was held down when the event occurred, otherwise false
    • getCharCode

      public Long getCharCode()
      Gets the pressed key character's Unicode
      Returns:
      The pressed key character's Unicode
    • getCode

      public String getCode()
      Gets the pressed key's code in a String format
      Returns:
      The pressed key's code in a String format (ex: "a", "enter" or "f1")
    • getCtrlKey

      public Boolean getCtrlKey()
      Determines if the CONTROL key was held down when the event occurred
      Returns:
      true, if the CONTROL button was held down when the event occurred, otherwise false
    • getKey

      public String getKey()
      Gets the pressed key's name
      Returns:

      The key name
      Possible values:

      • One character (like "a", "W", "4", "+" or "$")
      • Multiple characters (like "F1", "Enter", "HOME" or "CAPS LOCK")
      Note: If using Safari, the return value will be "undefined"
    • getKeyCode

      public Long getKeyCode()
      Gets the pressed key's Unicode
      Returns:
      The pressed key's Unicode
    • getLocation

      public Long getLocation()
      Gets the pressed key's location
      Returns:
      A number corresponding to the pressed key's location. Possible values:
      • 0. DOM_KEY_LOCATION_STANDARD : Keys that only appear on the keyboard once
      • 1. DOM_KEY_LOCATION_LEFT : Keys that appear on the left side
      • 2. DOM_KEY_LOCATION_RIGHT : Keys that appear on the right side
      • 3. DOM_KEY_LOCATION_NUMPAD :Keys that appear on the numpad
    • getMetaKey

      public Boolean getMetaKey()
      Determines if the Meta key was held down when the event occurred
      Returns:
      true, if the Meta button was held down when the event occurred, otherwise false
    • getShiftKey

      public Boolean getShiftKey()
      Determines if the SHIFT key was held down when the event occurred
      Returns:
      true, if the SHIFT button was held down when the event occurred, otherwise false
    • getWhich

      public Long getWhich()
      Gets the Unicode character code of the key
      Returns:
      The Unicode character code of the key