Class KeyEvent

java.lang.Object
icyllis.modernui.view.InputEvent
icyllis.modernui.view.KeyEvent

public class KeyEvent extends InputEvent
Object that reports key events (keyboard etc.). Modified for desktop application.
  • Field Details

  • Method Details

    • obtain

      @NonNull public static KeyEvent obtain(long eventTime, int action, int code, int repeat, int modifiers, int scancode, int flags)
    • getAction

      public final int getAction()
      Retrieve the action of this key event. May be either ACTION_DOWN or ACTION_UP.
      Returns:
      The event action: ACTION_DOWN or ACTION_UP.
    • getKeyCode

      public final int getKeyCode()
      Retrieve the key code of the key event.
      Returns:
      The key code of the event.
    • getScanCode

      public final int getScanCode()
      Retrieve the hardware key id of this key event. These values are not reliable and vary from device to device.
    • getRepeatCount

      public final int getRepeatCount()
      Retrieve the repeat count of the event. For key down events, this is the number of times the key has repeated with the first down starting at 0 and counting up from there. For key up events, this is always equal to zero. For multiple key events, this is the number of down/up pairs that have occurred.
      Returns:
      The number of times the key has repeated.
    • getModifiers

      public final int getModifiers()
      Returns the state of the modifier keys.
      Returns:
      An integer in which each bit set to 1 represents a pressed modifier key.
    • hasNoModifiers

      public final boolean hasNoModifiers()
      Returns true if no modifier keys are pressed.
      Returns:
      True if no modifier keys are pressed.
    • hasModifiers

      public final boolean hasModifiers(int modifiers)
      Returns true if only the specified modifiers keys are pressed. Returns false if a different combination of modifier keys are pressed.

      If the specified modifier mask includes non-directional modifiers, such as GLFW.GLFW_MOD_SHIFT, then this method ensures that the modifier is pressed on either side.

      Parameters:
      modifiers - The modifier keys to check. May be a combination of modifier keys. May be 0 to ensure that no modifier keys are pressed.
      Returns:
      true if only the specified modifier keys are pressed.
    • isShiftPressed

      public final boolean isShiftPressed()
      Returns the pressed state of the SHIFT key.
      Returns:
      true if the SHIFT key is pressed, false otherwise
    • isCtrlPressed

      public final boolean isCtrlPressed()
      Returns the pressed state of the CTRL key. If it's running on OSX, returns the pressed state of the SUPER key.
      Returns:
      true if the CTRL key is pressed, false otherwise
    • isAltPressed

      public final boolean isAltPressed()
      Returns the pressed state of the ALT key.
      Returns:
      true if the ALT key is pressed, false otherwise
    • isSuperPressed

      public final boolean isSuperPressed()
      Returns the pressed state of the SUPER key (a.k.a. META or WIN key).
      Returns:
      true if the SUPER key is pressed, false otherwise
    • isCapsLockOn

      public final boolean isCapsLockOn()
      Returns the locked state of the CAPS LOCK key.
      Returns:
      true if the CAPS LOCK key is on, false otherwise
    • isNumLockOn

      public final boolean isNumLockOn()
      Returns the locked state of the NUM LOCK key.
      Returns:
      true if the NUM LOCK key is on, false otherwise
    • getMappedChar

      public final char getMappedChar()
      Returns the alphabetic character represented by the key. You should check if this is a PRESS action.
      Returns:
      the alphabetic character represented by the key
    • recycle

      public void recycle()
      Recycles the event. This object should not be ever used after recycling.

      This method should only be called by system.

      Specified by:
      recycle in class InputEvent
    • copy

      @NonNull public InputEvent copy()
      Description copied from class: InputEvent
      Copies the event.
      Specified by:
      copy in class InputEvent
      Returns:
      A deep copy of the event.
    • getEventTime

      public long getEventTime()
      Description copied from class: InputEvent
      Get the time in milliseconds that this event object is created in the GLFW time base
      Specified by:
      getEventTime in class InputEvent
      Returns:
      the time this event occurred
    • getEventTimeNano

      public long getEventTimeNano()
      Description copied from class: InputEvent
      Get the precise time in nanoseconds that this event object is created in the GLFW time base
      Specified by:
      getEventTimeNano in class InputEvent
      Returns:
      the time this event occurred
    • isCanceled

      public final boolean isCanceled()
      For ACTION_UP events, indicates that the event has been canceled as per FLAG_CANCELED.
    • cancel

      public final void cancel()
      Description copied from class: InputEvent
      Marks the input event as being canceled.
      Specified by:
      cancel in class InputEvent
    • startTracking

      public final void startTracking()
      Call this during
      invalid reference
      Callback#onKeyDown
      to have the system track the key through its final up (possibly including a long press). Note that only one key can be tracked at a time -- if another key down event is received while a previous one is being tracked, tracking is stopped on the previous event.
    • isTracking

      public final boolean isTracking()
      For ACTION_UP events, indicates that the event is still being tracked from its initial down event as per FLAG_TRACKING.
    • isLongPress

      public final boolean isLongPress()
      For ACTION_DOWN events, indicates that the event has been canceled as per FLAG_LONG_PRESS.
    • isModifierKey

      public static boolean isModifierKey(int keyCode)
      Returns true if this key code is a modifier key.

      For the purposes of this function, KEY_CAPS_LOCK, KEY_SCROLL_LOCK, and KEY_NUM_LOCK are not considered modifier keys. Consequently, this function return false for those keys.

      Returns:
      True if the key code is one of modifier keys.