IInputReceiver
Last updated
Was this helpful?
Last updated
Was this helpful?
The IInputReceiver interface provides methods and properties common to all UI elements which can receive input from devices such as the or . Any object which implements the IInputReceiver can be assigned to the InputManager's InputReceiver.
Only one instance can be assigned as the InputManager.InputReceiver property. If assigned, this instance has a number of methods called upon being assigned as well as in response to input. Its OnFocusUpdate is also called every frame automatically.
FlatRedBall.Forms elements typically receive input in one of two ways:
In response to Cursor clicks. These events are ultimately raised by the underlying Gum objects (GraphicalUiElement)
In response to changes in a keyboard state or Xbox360GamePad which is polled every-frame.
Forms elements which need to poll input every frame should do so by implementing IInputReceiver and checking input in the OnFocusUpdate.
For example, the following code could be used to perform custom actions whenever the A button is pressed on a Forms control which implements IInputReceiver:
For a full example of implementation, see the ListBox implementation:
The IInputReceiver interface is designed to prevent multiple objects from receiving input. The most common way to do this is to have the IInputReceiver process input in its ReceiveInput method, then clear the input. For example, the following code can be used to move an object and clear the input.
IInputReceivers automatically receive input from the keyboard when they have focus. To prevent this from occurring the TakingInput property can be set to false:
This method is especially effective because ReceiveInput is called prior to the game's activity. For more information, see .