Class KeyEvent


public final class KeyEvent extends InputEvent
A keyboard event routed to the focused widget (bubbling to its ancestors until consumed). Key codes and modifiers follow Keys.

A key is told two ways. key() is the physical key, where it sits on the keyboard, named after the key at that place on a US layout: what a game wants, since W is up wherever the layout moved the letter. shortcutKey() is the key the active layout prints there when it is a letter or a digit: what a shortcut wants, since the user reads Ctrl+Z off the keycap, and on a French AZERTY keyboard the key printed Z is where a US layout has W.

  • Constructor Summary

    Constructors
    Constructor
    Description
    KeyEvent(int key, boolean pressed, boolean repeat, int modifiers)
    A key transition on a US layout, where the key printed on a keycap is the physical key's name: what a test types.
    KeyEvent(int key, int layoutCodePoint, boolean pressed, boolean repeat, int modifiers)
    A key transition.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether this is a press (or auto-repeat) rather than a release.
    boolean
     
    int
    key()
    The physical key, as a Keys constant: where it is on the keyboard, whatever the layout prints on it, named after the key at that place on a US layout.
    int
     
    int
    Modifier mask held during the event; test it with the Keys.MOD_* bits.
    int
    The key a shortcut is read from: the letter or digit the active layout prints on this key, as the Keys constant of that letter or digit, and key() for every other key.
     

    Methods inherited from class limn.scene.event.InputEvent

    consume, isConsumed

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • KeyEvent

      public KeyEvent(int key, boolean pressed, boolean repeat, int modifiers)
      A key transition on a US layout, where the key printed on a keycap is the physical key's name: what a test types.
      Parameters:
      key - the physical key, a Keys constant
      pressed - a press or an auto-repeat rather than a release
      repeat - an auto-repeat
      modifiers - the Keys.MOD_* bits held
    • KeyEvent

      public KeyEvent(int key, int layoutCodePoint, boolean pressed, boolean repeat, int modifiers)
      A key transition.
      Parameters:
      key - the physical key, a Keys constant
      layoutCodePoint - what the active layout types at that key with no modifier held, or 0 for a key that types nothing (an arrow, a function key)
      pressed - a press or an auto-repeat rather than a release
      repeat - an auto-repeat
      modifiers - the Keys.MOD_* bits held
  • Method Details

    • key

      public int key()
      The physical key, as a Keys constant: where it is on the keyboard, whatever the layout prints on it, named after the key at that place on a US layout.
    • layoutCodePoint

      public int layoutCodePoint()
      Returns:
      what the active layout types at this key with no modifier held, as a code point, or 0 for a key that types nothing
    • shortcutKey

      public int shortcutKey()
      The key a shortcut is read from: the letter or digit the active layout prints on this key, as the Keys constant of that letter or digit, and key() for every other key. On AZERTY the key where a US layout has W answers Keys.Z, so Ctrl+Z is the key the user sees Z on; a layout whose letters are not Latin (Cyrillic, Greek) answers the physical key, as native applications do, so Ctrl+Z stays where Z is on a US keyboard.
      Returns:
      a Keys constant
    • isPressed

      public boolean isPressed()
      Whether this is a press (or auto-repeat) rather than a release.
    • isRepeat

      public boolean isRepeat()
      Returns:
      true for auto-repeat presses
    • modifiers

      public int modifiers()
      Modifier mask held during the event; test it with the Keys.MOD_* bits.
    • toString

      public String toString()
      Overrides:
      toString in class Object