Package playn.core
Class Keyboard
java.lang.Object
playn.core.Keyboard
Defines and dispatches keyboard events. Three events are generated by keyboard input:
- When any key is depressed, a
Keyboard.KeyEventis 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.TypedEventis 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.KeyEventis emitted, indicating the logical key that was released.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe base class for all keyboard events.static classAn event dispatched for key press/release.static classA slot which only dispatches onKeyboard.KeyEvents.static enumEnumerates the different available mobile keyboard types.static classAn event dispatched when a printable character is typed.static classA slot which only dispatches onKeyboard.TypedEvents. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Function<Keyboard.Event,Keyboard.KeyEvent> Returns a collector function for key events forkey.static Keyboard.KeyEventisKey(Key key, Keyboard.Event event) A collector function for key events forkey.static Keyboard.KeyEventkeyEvents(Keyboard.Event event) Checks whethereventis aKeyEventand returns it (casted appropriately) if so.static Keyboard.TypedEventtypedEvents(Keyboard.Event event) Checks whethereventis aTypedEventand returns it (casted appropriately) if so.
-
Constructor Details
-
Keyboard
public Keyboard()
-
-
Method Details
-
keyEvents
Checks whethereventis aKeyEventand returns it (casted appropriately) if so. Returnsnullotherwise. 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
Checks whethereventis aTypedEventand returns it (casted appropriately) if so. Returnsnullotherwise. 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
A collector function for key events forkey. 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
Returns a collector function for key events forkey. 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 });
-