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.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The base class for all keyboard events.static class
An event dispatched for key press/release.static class
A slot which only dispatches onKeyboard.KeyEvent
s.static enum
Enumerates the different available mobile keyboard types.static class
An event dispatched when a printable character is typed.static class
A slot which only dispatches onKeyboard.TypedEvent
s. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Function<Keyboard.Event,
Keyboard.KeyEvent> Returns a collector function for key events forkey
.static Keyboard.KeyEvent
isKey
(Key key, Keyboard.Event event) A collector function for key events forkey
.static Keyboard.KeyEvent
keyEvents
(Keyboard.Event event) Checks whetherevent
is aKeyEvent
and returns it (casted appropriately) if so.static Keyboard.TypedEvent
typedEvents
(Keyboard.Event event) Checks whetherevent
is aTypedEvent
and returns it (casted appropriately) if so.
-
Constructor Details
-
Keyboard
public Keyboard()
-
-
Method Details
-
keyEvents
Checks whetherevent
is aKeyEvent
and returns it (casted appropriately) if so. Returnsnull
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
Checks whetherevent
is aTypedEvent
and returns it (casted appropriately) if so. Returnsnull
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
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 });
-