Click or drag to resize
DigitalRuneIInputCommand Interface
Defines a command that is activated by user input.

Namespace: DigitalRune.Game.Input
Assembly: DigitalRune.Game.Input (in DigitalRune.Game.Input.dll) Version: 1.8.0.0 (1.8.0.14467)
Syntax
public interface IInputCommand : INamedObject

The IInputCommand type exposes the following members.

Methods
  NameDescription
Public methodUpdate
Updates internal values of this command. This method is called automatically in each frame by the input service.
Top
Properties
  NameDescription
Public propertyInputService
Gets or sets the input service.
Public propertyName
Gets the name.
(Inherited from INamedObject.)
Public propertyValue
Gets the value.
Top
Remarks

Input commands translate raw input into (such as button presses, key combinations, etc.) to semantic actions (such as "Forward", "Jump", "Shoot", etc.).Input commands are managed by the InputService. Input commands can be added or removed from the input service by adding or removing them from the Commands collection. The input commands are identified by their Name in the Commands collection.

When the input service is updated it calls the method Update(TimeSpan) of all registered input commands. In this method the input commands can check the user input and update their Value accordingly. For example, the input command "Jump" might check whether the user has pressed the SPACE key and set the value to 1 if the key is down.

Other game components can check the command and do not need to know which user input triggered the action. For example:

C#
if (InputService.Commands["Jump"].Value > 0)
{
  // Let the player character jump.
  ...
}
The input mapping can be reconfigured at runtime without affecting other game components.

Input commands should have a unique Name. The name must not be changed while the command is added to an IInputService. Here are examples for command names in a game: "Forward", "Strafe", "Turn", "Jump", "Shoot", etc. Typically, command names describe the intention of the player.

The Value indicates whether the command is active. A value of 0 indicates that the action is inactive. A value of 1 typically indicates that the command is active - the user wants to perform the action. Depending on the type of action, the value can also be negative. For example, the "Forward" command might use a value of 1 to indicate that the user wants to move forward and a value of -1 to indicate that the user wants to move backward. A value of 0.5 can indicate that the user wants to move with half speed, which can result from an analog input device.

The property InputService is automatically set when the command is added to an input service. The method Update(TimeSpan) is called in each frame by the InputService to do any time intensive work. For instance, if the command smooths input values using a low-pass filter, this is best done in the Update(TimeSpan) method.

This interface does not define how commands use the IsHandled flags (IsKeyboardHandled, etc.) of the input service.

See Also