InputManager
is responsible for converting input events received from the Key, Mouse and Joy Input implementations into an abstract, input device independent representation that user code can use. By default an InputManager
is included with every Application instance for use in user code to query input, unless the Application is created as headless or with input explicitly disabled.
The input manager has two concepts, a {@link Trigger} and a mapping.A trigger represents a specific input trigger, such as a key button, or a mouse axis. A mapping represents a link onto one or several triggers, when the appropriate trigger is activated (e.g. a key is pressed), the mapping will be invoked. Any listeners registered to receive an event from the mapping will have an event raised.
There are two types of events that {@link InputListener input listeners}can receive, one is {@link ActionListener#onAction(java.lang.String,boolean,float) action}events and another is {@link AnalogListener#onAnalog(java.lang.String,float,float) analog}events.
onAction
events are raised when the specific input activates or deactivates. For a digital input such as key press, the onAction()
event will be raised with the isPressed
argument equal to true, when the key is released, onAction
is called again but this time with the isPressed
argument set to false. For analog inputs, the onAction
method will be called any time the input is non-zero, however an exception to this is for joystick axis inputs, which are only called when the input is above the {@link InputManager#setAxisDeadZone(float) dead zone}.
onAnalog
events are raised every frame while the input is activated. For digital inputs, every frame that the input is active will cause the onAnalog
method to be called, the argument value
argument will equal to the frame's time per frame (TPF) value but only for digital inputs. For analog inputs however, the value
argument will equal the actual analog value.
InputManager
supports event listener (EventListener
) objects. These listeners can be added to entities in the world in order to allow these entities to respond to events. These events can be generated as a result of user input or can be programmatically generated by other parts of the client. InputManager
also supports a set of global event listeners. These are independent of any entities. The system always delivers all events to global event listeners which are willing to consume these events. Note: the return value of propagateToParent()
for global listeners is ignored. Note: The pickDetails
field of an event is null for events received by the global listeners. InputManager
provides a more general model of focus. InputManager
provides "focus sets" for different classes of events. Each distinct event class can have its own focus set. A focus set is a set of one or more entities that have focus for that class of event. For example, the KeyEvent3D
class can have a focus set consisting of Entity1 and the MouseEvent3D
class can have a focus set consisting of Entity2 and Entity3. Unlike Wonderland Release 0.4, each event class can have a different set of focussed entities. Notice also that there can be multiple focussed entities instead of just one. When an entity is handed to an event listener via an event listener method such as, consumesEvent
etc., that method can determine the entity to which the event was distributed by calling Event.getEntity()
. The method can determine if the entity has focus by calling Event.isFocussed()
. (Note that isFocussed
returns whether the entity had focus at the time the event was delivered to the listener). isFocussed
flag or ignore it. For example, a shared app event listener could be written to ignore events when the entity of the shared app does not have focus. Or, a 3D "xeyes" type of app could be written to accept all mouse motion events, regardless of whether their entity has focus, and change the gaze of the eyes to follow the mouse pointer's location no matter where it moves on the screen. InputManager
merely provides the mechanism. The goal is to allow multiple and different focus managers to be experimented with over time.
@author deronj
|
|
|
|