org.jrabbit.base.input
Class KeyboardHandler

java.lang.Object
  extended by org.jrabbit.base.input.KeyboardHandler

public final class KeyboardHandler
extends java.lang.Object

KeyboardHandler is a static class that provides the default methods for reacting to player input via the keyboard. It is automatically updated in the main game loop. NOTE: It's possible that a different input setup will better suit your needs. If this is the case, you should be aware that by default, KeyboardHandler "eats" all Keyboard events. You can turn this activity off, however, and interpret them with your own code.

Author:
Chris Molini

Field Summary
private static boolean activated
          Whether or not KeyboardHandler should parse Keyboard events.
private static java.util.ArrayList<java.lang.Character> chars
          The list of every character that has been typed.
private static java.util.ArrayList<KeyEventListener> eventListeners
          The list of objects listening to the Keyboard for complete LWJGL events.
private static java.util.ArrayList<java.lang.Integer> keysPressed
          The list of keys that have been pressed since the last update cycle.
private static java.util.ArrayList<java.lang.Integer> keysReleased
          The list of keys that have been released since the last update cycle.
private static java.util.ArrayList<KeyboardListener> listeners
          The list of objects listening to the Keyboard for input changes.
 
Constructor Summary
KeyboardHandler()
           
 
Method Summary
static void activate(boolean active)
          Determines whether or not Keyboard events should be processed.
static boolean activated()
          Learns if the KeyboardHandler is active.
static java.util.Collection<KeyEventListener> eventListeners()
          Accesses the list of Keyboard Event listeners.
static boolean isKeyDown(int key)
          Checks if a key is being continuously held down.
static java.util.Collection<KeyboardListener> listeners()
          Accesses the list of Keyboard listeners.
static java.util.ArrayList<java.lang.Character> typedCharacters()
          Accesses the list of all characters that were typed since the last update.
static void update()
          Advances the KeyboardHandler.
static boolean wasKeyPressed(int key)
          Checks if a key was initially pressed since the last update cycle.
static boolean wasKeyReleased(int key)
          Checks if a key was released since the last update cycle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activated

private static boolean activated
Whether or not KeyboardHandler should parse Keyboard events.


keysPressed

private static java.util.ArrayList<java.lang.Integer> keysPressed
The list of keys that have been pressed since the last update cycle.


keysReleased

private static java.util.ArrayList<java.lang.Integer> keysReleased
The list of keys that have been released since the last update cycle.


chars

private static java.util.ArrayList<java.lang.Character> chars
The list of every character that has been typed.


listeners

private static java.util.ArrayList<KeyboardListener> listeners
The list of objects listening to the Keyboard for input changes.


eventListeners

private static java.util.ArrayList<KeyEventListener> eventListeners
The list of objects listening to the Keyboard for complete LWJGL events.

Constructor Detail

KeyboardHandler

public KeyboardHandler()
Method Detail

activate

public static void activate(boolean active)
Determines whether or not Keyboard events should be processed. Use this to turn off KeyboardHandler calculations if you want to use a different input system for handling Keyboard events. NOTE: Even if this is turned off, isKeyDown() will return the correct values, as it delegates the check to Keyboard.

Parameters:
active - Whether or not the KeyboardHandler should process Keyboard events.

activated

public static boolean activated()
Learns if the KeyboardHandler is active.

Returns:
True if Keyboard events are being processed, false if not.

listeners

public static java.util.Collection<KeyboardListener> listeners()
Accesses the list of Keyboard listeners. NOTE: This is the means that should be used to add and remove new KeyboardListeners.

Returns:
All of the objects currently listening for input changes.

eventListeners

public static java.util.Collection<KeyEventListener> eventListeners()
Accesses the list of Keyboard Event listeners. NOTE: This is the means that should be used to add and remove new KeyEventListeners.

Returns:
All of the objects currently listening for Keyboard events.

isKeyDown

public static boolean isKeyDown(int key)
Checks if a key is being continuously held down.

Parameters:
key - The key to check. (Use the identifiers in Keyboard.)
Returns:
True if the key is held down, false if not.

wasKeyPressed

public static boolean wasKeyPressed(int key)
Checks if a key was initially pressed since the last update cycle.

Parameters:
key - The key to check. (Use the identifiers in Keyboard.)
Returns:
True if the key was first pressed since the last update, false if not.

wasKeyReleased

public static boolean wasKeyReleased(int key)
Checks if a key was released since the last update cycle.

Parameters:
key - The key to check. (Use the identifiers in Keyboard.)
Returns:
True if the key was released since the last update, false if not.

typedCharacters

public static java.util.ArrayList<java.lang.Character> typedCharacters()
Accesses the list of all characters that were typed since the last update.

Returns:
Every character that has been typed.

update

public static void update()
Advances the KeyboardHandler. This clears all old stored input data (the lists of pressed and released keys and all typed characters). Then, if activated, recalculates the input data by polling Keyboard events.