Package playn.core

Class Keyboard

java.lang.Object
playn.core.Keyboard

public abstract class Keyboard extends Object
Defines and dispatches keyboard events. Three events are generated by keyboard input:
  • When any key is depressed, a Keyboard.KeyEvent is emitted indicating the logical key that was depressed.
  • If the depressed key also corresponds to a printable character ('c' for example, but not shift or alt), a Keyboard.TypedEvent is emitted to inform the app of the typed character. The typed character will account for whether the shift key is depressed and will be appropriately mapped to the uppercase equivalent or the appropriate alternate character (for example, # for 3, in the US keyboard layout). The typed event is delivered immediately after the pressed event.
  • When a key is released, a Keyboard.KeyEvent is emitted, indicating the logical key that was released.
  • Constructor Details

    • Keyboard

      public Keyboard()
  • Method Details

    • keyEvents

      public static Keyboard.KeyEvent keyEvents(Keyboard.Event event)
      Checks whether event is a KeyEvent and returns it (casted appropriately) if so. Returns null otherwise. Use it to obtain only key events like so:
      Input.keyboardEvents.collect(Keyboard::keyEvents).connect(event -> {
         // handle key events here (event has type KeyEvent)
       });
       
    • typedEvents

      public static Keyboard.TypedEvent typedEvents(Keyboard.Event event)
      Checks whether event is a TypedEvent and returns it (casted appropriately) if so. Returns null otherwise. Use it to obtain only typed events like so:
      Input.keyboardEvents.collect(Keyboard::typedEvents).connect(event -> {
         // handle typed events here (event has type TypedEvent)
       });
       
    • isKey

      public static Keyboard.KeyEvent isKey(Key key, Keyboard.Event event)
      A collector function for key events for key. Use it to obtain only events for a particular key like so:
      
       Input.keyboardEvents.collect(ev -> Keyboard.isKey(Key.X, ev)).connect(event -> {
         // handle the 'x' key being pressed or released
       });
       
    • isKey

      public static Function<Keyboard.Event,Keyboard.KeyEvent> isKey(Key key)
      Returns a collector function for key events for key. Use it to obtain only events for a particular key like so:
      
       Input.keyboardEvents.collect(Keyboard.isKey(Key.X)).connect(event -> {
         // handle the 'x' key being pressed or released
       });