Package de.gurkenlabs.litiengine.input
Class Keyboard
java.lang.Object
de.gurkenlabs.litiengine.input.Keyboard
- All Implemented Interfaces:
IKeyboard
,IUpdateable
,java.awt.KeyEventDispatcher
public final class Keyboard
extends java.lang.Object
implements java.awt.KeyEventDispatcher, IKeyboard, IUpdateable
Nested Class Summary
Nested classes/interfaces inherited from interface de.gurkenlabs.litiengine.input.IKeyboard
IKeyboard.KeyPressedListener, IKeyboard.KeyReleasedListener, IKeyboard.KeyTypedListener
Method Summary
Modifier and Type Method Description void
addKeyListener(java.awt.event.KeyListener listener)
Register for key events.void
clearExplicitListeners()
Removes all registered event consumers from the Keyboard instance.void
consumeAlt(boolean consume)
Specifies whether the engine should consume key events with the ALT modifier.boolean
dispatchKeyEvent(java.awt.event.KeyEvent e)
boolean
isPressed(int keyCode)
Checks whether the key with the specifiedkeyCode
is currently being pressed.void
onKeyPressed(int keyCode, IKeyboard.KeyPressedListener listener)
Adds the specified key pressed listener to receive events when the key with the definedkeyCode
has been pressed.void
onKeyPressed(IKeyboard.KeyPressedListener listener)
Adds the specified key pressed listener to receive events when any key has been pressed.void
onKeyReleased(int keyCode, IKeyboard.KeyReleasedListener listener)
Adds the specified key released listener to receive events when the key with the definedkeyCode
has been released.void
onKeyReleased(IKeyboard.KeyReleasedListener listener)
Adds the specified key released listener to receive events when any key has been released.void
onKeyTyped(int keyCode, IKeyboard.KeyTypedListener listener)
Adds the specified key typed listener to receive events when the key with the definedkeyCode
has been typed.void
onKeyTyped(IKeyboard.KeyTypedListener listener)
Adds the specified key typed listener to receive events when any key has been typed.void
removeKeyListener(java.awt.event.KeyListener listener)
Unregister the specified listener from key events.void
removeKeyPressedListener(int keyCode, IKeyboard.KeyPressedListener listener)
Unregister the specified listener from key pressed events.void
removeKeyPressedListener(IKeyboard.KeyPressedListener listener)
Unregister the specified listener from key pressed events.void
removeKeyReleasedListener(int keyCode, IKeyboard.KeyReleasedListener listener)
Unregister the specified listener from key released events.void
removeKeyReleasedListener(IKeyboard.KeyReleasedListener listener)
Unregister the specified listener from key released events.void
removeKeyTypedListener(int keyCode, IKeyboard.KeyTypedListener listener)
Unregister the specified listener from key typed events.void
removeKeyTypedListener(IKeyboard.KeyTypedListener listener)
Unregister the specified listener from key typed events.void
update()
This method is called by the game loop on all objects that are attached to the loop.boolean
wasReleased(int keyCode)
Checks whether the key with the specifiedkeyCode
was recently released.
Method Details
consumeAlt
public void consumeAlt(boolean consume)Description copied from interface:IKeyboard
Specifies whether the engine should consume key events with the ALT modifier.This is useful to prevent unintended behavior of the default key processing.
- Specified by:
consumeAlt
in interfaceIKeyboard
- Parameters:
consume
- True if the events with the ALT modifier should be consumed.- See Also:
InputEvent.consume()
,InputEvent.isAltDown()
dispatchKeyEvent
public boolean dispatchKeyEvent(java.awt.event.KeyEvent e)- Specified by:
dispatchKeyEvent
in interfacejava.awt.KeyEventDispatcher
isPressed
public boolean isPressed(int keyCode)Description copied from interface:IKeyboard
Checks whether the key with the specifiedkeyCode
is currently being pressed.- Specified by:
isPressed
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode to check for.- Returns:
- True if the key with the specified code is currently pressed.
- See Also:
IKeyboard.onKeyPressed(KeyPressedListener)
,IKeyboard.onKeyPressed(int, KeyPressedListener)
wasReleased
public boolean wasReleased(int keyCode)Description copied from interface:IKeyboard
Checks whether the key with the specifiedkeyCode
was recently released.- Specified by:
wasReleased
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode to check for.- Returns:
- True if the key with the specified code was recently released.
- See Also:
IKeyboard.onKeyReleased(KeyReleasedListener)
,IKeyboard.onKeyReleased(int, KeyReleasedListener)
onKeyPressed
Description copied from interface:IKeyboard
Adds the specified key pressed listener to receive events when the key with the definedkeyCode
has been pressed.- Specified by:
onKeyPressed
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode to capture the key pressed event for.listener
- The listener to add.- See Also:
KeyListener.keyPressed(KeyEvent)
,KeyEvent.KEY_PRESSED
removeKeyPressedListener
Description copied from interface:IKeyboard
Unregister the specified listener from key pressed events.- Specified by:
removeKeyPressedListener
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode for which to remove the listener.listener
- The listener to remove.
onKeyReleased
Description copied from interface:IKeyboard
Adds the specified key released listener to receive events when the key with the definedkeyCode
has been released.- Specified by:
onKeyReleased
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode to capture the key released event for.listener
- The listener to add.- See Also:
KeyListener.keyReleased(KeyEvent)
,KeyEvent.KEY_RELEASED
removeKeyReleasedListener
Description copied from interface:IKeyboard
Unregister the specified listener from key released events.- Specified by:
removeKeyReleasedListener
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode for which to remove the listener.listener
- The listener to remove.
onKeyTyped
Description copied from interface:IKeyboard
Adds the specified key typed listener to receive events when the key with the definedkeyCode
has been typed.- Specified by:
onKeyTyped
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode to capture the key typed event for.listener
- The listener to add.- See Also:
KeyListener.keyTyped(KeyEvent)
,KeyEvent.KEY_TYPED
removeKeyTypedListener
Description copied from interface:IKeyboard
Unregister the specified listener from key typed events.- Specified by:
removeKeyTypedListener
in interfaceIKeyboard
- Parameters:
keyCode
- The keyCode for which to remove the listener.listener
- The listener to remove.
onKeyPressed
Description copied from interface:IKeyboard
Adds the specified key pressed listener to receive events when any key has been pressed.- Specified by:
onKeyPressed
in interfaceIKeyboard
- Parameters:
listener
- The listener to add.- See Also:
KeyListener.keyPressed(KeyEvent)
,KeyEvent.KEY_PRESSED
removeKeyPressedListener
Description copied from interface:IKeyboard
Unregister the specified listener from key pressed events.- Specified by:
removeKeyPressedListener
in interfaceIKeyboard
- Parameters:
listener
- The listener to remove.
onKeyReleased
Description copied from interface:IKeyboard
Adds the specified key released listener to receive events when any key has been released.- Specified by:
onKeyReleased
in interfaceIKeyboard
- Parameters:
listener
- The listener to add.- See Also:
KeyListener.keyReleased(KeyEvent)
,KeyEvent.KEY_RELEASED
removeKeyReleasedListener
Description copied from interface:IKeyboard
Unregister the specified listener from key released events.- Specified by:
removeKeyReleasedListener
in interfaceIKeyboard
- Parameters:
listener
- The listener to remove.
onKeyTyped
Description copied from interface:IKeyboard
Adds the specified key typed listener to receive events when any key has been typed.- Specified by:
onKeyTyped
in interfaceIKeyboard
- Parameters:
listener
- The listener to add.- See Also:
KeyListener.keyTyped(KeyEvent)
,KeyEvent.KEY_TYPED
removeKeyTypedListener
Description copied from interface:IKeyboard
Unregister the specified listener from key typed events.- Specified by:
removeKeyTypedListener
in interfaceIKeyboard
- Parameters:
listener
- The listener to remove.
clearExplicitListeners
public void clearExplicitListeners()Description copied from interface:IKeyboard
Removes all registered event consumers from the Keyboard instance. This does not affect registeredKeyListener
instances.- Specified by:
clearExplicitListeners
in interfaceIKeyboard
- See Also:
IKeyboard.onKeyPressed(KeyPressedListener)
,IKeyboard.onKeyPressed(int, KeyPressedListener)
,IKeyboard.onKeyReleased(KeyReleasedListener)
,IKeyboard.onKeyReleased(int, KeyReleasedListener)
,IKeyboard.onKeyTyped(KeyTypedListener)
,IKeyboard.onKeyTyped(int, KeyTypedListener)
addKeyListener
public void addKeyListener(java.awt.event.KeyListener listener)Description copied from interface:IKeyboard
Register for key events.- Specified by:
addKeyListener
in interfaceIKeyboard
- Parameters:
listener
- The listener to add.
removeKeyListener
public void removeKeyListener(java.awt.event.KeyListener listener)Description copied from interface:IKeyboard
Unregister the specified listener from key events.- Specified by:
removeKeyListener
in interfaceIKeyboard
- Parameters:
listener
- The listener to remove.
update
public void update()Description copied from interface:IUpdateable
This method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using theClientConfiguration
.- Specified by:
update
in interfaceIUpdateable
- See Also:
ClientConfiguration.setMaxFps(int)