com.jme.input
Class InputHandler

java.lang.Object
  extended bycom.jme.input.InputHandler
Direct Known Subclasses:
FirstPersonHandler, IngameHandler, MenuHandler, NodeHandler

public class InputHandler
extends java.lang.Object

InputHandler handles mouse and key inputs. Inputs are added and whenever update is called whenever action needs to take place (usually every frame). Mouse actions are performed every update call. Keyboard actions are performed only if the correct key is pressed.

Version:
$Id: InputHandler.java,v 1.17 2004/11/08 22:26:09 guurk Exp $
Author:
Mark Powell, Jack Lindamood - (javadoc only)

Field Summary
protected  java.util.ArrayList buffKeyActions
          Actions that just get back an event driven action
protected  java.util.ArrayList keyActions
          List of keyboard actions.
protected  KeyBindingManager keyboard
          The keyboard where valid key actions are taken from in update.
protected  Mouse mouse
          The mouse where valid mouse actions are taken from in update.
protected  java.util.ArrayList mouseActions
          List of mouse actions.
protected  boolean useBufferedKeyboard
          setup only when the buffKeyActions list has elements
 
Constructor Summary
InputHandler()
          Creates a new input handler.
 
Method Summary
 void addAction(KeyInputAction inputAction)
          Adds a keyboard input action to be polled by this handler during update.
 void addAction(MouseInputAction mouseAction)
          Adds a mouse input action to be polled by this handler during update.
 void addBufferedKeyAction(KeyInputAction keyInputAction)
          Used to set actions which will be called based on event driven keyboard actions
 void addKeyboardAction(java.lang.String keyIdent, int keyInputValue, KeyInputAction action)
          Binds to the key an action and an identification string.
 void clearKeyboardActions()
          Clears all keyboard actions currently stored.
 void clearMouseActions()
          Clears all mouse actions currently stored.
 KeyBindingManager getKeyBindingManager()
          Returns the currently assigned keybard to receive key inputs.
 Mouse getMouse()
          Returns the mouse currently receiving inputs by this handler.
 void removeAction(KeyInputAction inputAction)
          Removes a keyboard input action from the list of keyActions that are polled during update.
 void removeAction(MouseInputAction mouseAction)
          Removes a mouse input action from the list of mouseActions that are polled during update.
 void setKeyBindingManager(KeyBindingManager keyboard)
          Sets the keyboard that will receive key inputs by this handler.
 void setKeySpeed(float speed)
          Sets the speed of all key actions currently defined by this handler to the given value.
 void setMouse(Mouse mouse)
          Sets the mouse to receive mouse inputs from.
 void setMouseSpeed(float speed)
          Sets the speed of all mouse actions currently defined by this handler to the given value.
 void update(float time)
          Checks all key and mouse actions to see if they are valid commands.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyActions

protected java.util.ArrayList keyActions
List of keyboard actions. They are performed in update if valid.


buffKeyActions

protected java.util.ArrayList buffKeyActions
Actions that just get back an event driven action


mouseActions

protected java.util.ArrayList mouseActions
List of mouse actions. They are performed in update.


keyboard

protected KeyBindingManager keyboard
The keyboard where valid key actions are taken from in update.


mouse

protected Mouse mouse
The mouse where valid mouse actions are taken from in update.


useBufferedKeyboard

protected boolean useBufferedKeyboard
setup only when the buffKeyActions list has elements

Constructor Detail

InputHandler

public InputHandler()
Creates a new input handler. By default, there are no keyboard actions or mouse actions defined.

Method Detail

setKeyBindingManager

public void setKeyBindingManager(KeyBindingManager keyboard)
Sets the keyboard that will receive key inputs by this handler.

Parameters:
keyboard - The keyboard to receive key inputs.

getKeyBindingManager

public KeyBindingManager getKeyBindingManager()
Returns the currently assigned keybard to receive key inputs.

Returns:
This handler's keyboard.

setMouse

public void setMouse(Mouse mouse)
Sets the mouse to receive mouse inputs from.

Parameters:
mouse - This handler's new mouse.

getMouse

public Mouse getMouse()
Returns the mouse currently receiving inputs by this handler.

Returns:
This handler's mouse.

setKeySpeed

public void setKeySpeed(float speed)
Sets the speed of all key actions currently defined by this handler to the given value.

Parameters:
speed - The new speed for all currently defined key actions.
See Also:
KeyInputAction.setSpeed(float)

setMouseSpeed

public void setMouseSpeed(float speed)
Sets the speed of all mouse actions currently defined by this handler to the given value.

Parameters:
speed - The new speed for all currently defined mouse actions.
See Also:
InputAction.setSpeed(float)

addAction

public void addAction(KeyInputAction inputAction)
Adds a keyboard input action to be polled by this handler during update.

Parameters:
inputAction - The input action to be added

addKeyboardAction

public void addKeyboardAction(java.lang.String keyIdent,
                              int keyInputValue,
                              KeyInputAction action)
Binds to the key an action and an identification string. The identification maps to the key and the action will receive updates on the key.

Parameters:
keyIdent - A string identifying this key/action purpose. IE "jump_key"
keyInputValue - A key that will fire this action. IE KeyInput.KEY_SPACE
action - An AbstractInputAction that is performed on the keyInputValue.

addBufferedKeyAction

public void addBufferedKeyAction(KeyInputAction keyInputAction)
Used to set actions which will be called based on event driven keyboard actions

Parameters:
keyInputAction - AbstractInputAction that is performed on key event the key value of the action will be changed dynamically

addAction

public void addAction(MouseInputAction mouseAction)
Adds a mouse input action to be polled by this handler during update.

Parameters:
mouseAction - The input action to be added

removeAction

public void removeAction(KeyInputAction inputAction)
Removes a keyboard input action from the list of keyActions that are polled during update.

Parameters:
inputAction - The action to remove.

clearKeyboardActions

public void clearKeyboardActions()
Clears all keyboard actions currently stored.


clearMouseActions

public void clearMouseActions()
Clears all mouse actions currently stored.


removeAction

public void removeAction(MouseInputAction mouseAction)
Removes a mouse input action from the list of mouseActions that are polled during update.

Parameters:
mouseAction - The action to remove.

update

public void update(float time)
Checks all key and mouse actions to see if they are valid commands. If so, performAction is called on the command with the given time.

Parameters:
time - The time to pass to every key and mouse action that is active.