Table of Contents

Class InputManager

Namespace
Stride.Input
Assembly
Stride.Input.dll

Manages collecting input from connected input device in the form of IInputDevice objects. Also provides some convenience functions for most commonly used devices

public class InputManager : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IInputEventListener<KeyEvent>, IInputEventListener<PointerEvent>, IInputEventListener<MouseWheelEvent>, IInputEventListener
Inheritance
InputManager
Implements
Inherited Members
Extension Methods

Constructors

InputManager()

Initializes a new instance of the InputManager class.

public InputManager()

Fields

GameControllerAxisDeadZone

The deadzone amount applied to all game controller axes

public static float GameControllerAxisDeadZone

Field Value

float

Properties

AbsoluteMouseDelta

Mouse movement in device coordinates

public Vector2 AbsoluteMouseDelta { get; }

Property Value

Vector2

AbsoluteMousePosition

Mouse coordinates in device coordinates

public Vector2 AbsoluteMousePosition { get; }

Property Value

Vector2

Accelerometer

Gets the reference to the accelerometer sensor. The accelerometer measures all the acceleration forces applied on the device.

public IAccelerometerSensor Accelerometer { get; }

Property Value

IAccelerometerSensor

Compass

Gets the reference to the compass sensor. The compass measures the angle between the device top and the north.

public ICompassSensor Compass { get; }

Property Value

ICompassSensor

DefaultGamePad

Gets the first gamepad that was added to the device

public IGamePadDevice DefaultGamePad { get; }

Property Value

IGamePadDevice

DownButtons

The mouse buttons that are down

public IReadOnlySet<MouseButton> DownButtons { get; }

Property Value

IReadOnlySet<MouseButton>

DownKeys

The keys that are down

public IReadOnlySet<Keys> DownKeys { get; }

Property Value

IReadOnlySet<Keys>

Events

All input events that happened since the last frame

public IReadOnlyList<InputEvent> Events { get; }

Property Value

IReadOnlyList<InputEvent>

GameControllerCount

Gets the number of game controllers connected.

public int GameControllerCount { get; }

Property Value

int

The number of game controllers connected.

GameControllers

Gets the collection of connected game controllers

public IReadOnlyList<IGameControllerDevice> GameControllers { get; }

Property Value

IReadOnlyList<IGameControllerDevice>

GamePadCount

Gets the number of gamepads connected.

public int GamePadCount { get; }

Property Value

int

The number of gamepads connected.

GamePads

Gets the collection of connected gamepads

public IReadOnlyList<IGamePadDevice> GamePads { get; }

Property Value

IReadOnlyList<IGamePadDevice>

GestureEvents

Gets the collection of gesture events since the previous updates.

public IReadOnlyList<GestureEvent> GestureEvents { get; }

Property Value

IReadOnlyList<GestureEvent>

The gesture events.

Gestures

List of the gestures to recognize.

public TrackingCollection<GestureConfig> Gestures { get; }

Property Value

TrackingCollection<GestureConfig>

Gravity

Gets the reference to the gravity sensor. The gravity sensor measures the gravity vector applied to the device.

public IGravitySensor Gravity { get; }

Property Value

IGravitySensor

Gyroscope

Gets the reference to the gyroscope sensor. The gyroscope measures the rotation speed of the device.

public IGyroscopeSensor Gyroscope { get; }

Property Value

IGyroscopeSensor

HasDownKeys

Determines whether one or more keys are down

public bool HasDownKeys { get; }

Property Value

bool

true if one or more keys are down; otherwise, false.

HasDownMouseButtons

Determines whether one or more of the mouse buttons are down

public bool HasDownMouseButtons { get; }

Property Value

bool

true if one or more of the mouse buttons are down; otherwise, false.

HasGameController

Gets a value indicating whether game controllers are available.

public bool HasGameController { get; }

Property Value

bool

true if game controllers are available; otherwise, false.

HasGamePad

Gets a value indicating whether gamepads are available.

public bool HasGamePad { get; }

Property Value

bool

true if gamepads are available; otherwise, false.

HasKeyboard

Gets a value indicating whether the keyboard is available.

public bool HasKeyboard { get; }

Property Value

bool

true if the keyboard is available; otherwise, false.

HasMouse

Gets a value indicating whether the mouse is available.

public bool HasMouse { get; }

Property Value

bool

true if the mouse is available; otherwise, false.

HasPointer

Gets a value indicating whether pointer device is available.

public bool HasPointer { get; }

Property Value

bool

true if pointer devices are available; otherwise, false.

HasPressedKeys

Determines whether one or more keys are pressed

public bool HasPressedKeys { get; }

Property Value

bool

true if one or more keys are pressed; otherwise, false.

HasPressedMouseButtons

Determines whether one or more of the mouse buttons are pressed

public bool HasPressedMouseButtons { get; }

Property Value

bool

true if one or more of the mouse buttons are pressed; otherwise, false.

HasReleasedKeys

Determines whether one or more keys are released

public bool HasReleasedKeys { get; }

Property Value

bool

true if one or more keys are released; otherwise, false.

HasReleasedMouseButtons

Determines whether one or more of the mouse buttons are released

public bool HasReleasedMouseButtons { get; }

Property Value

bool

true if one or more of the mouse buttons are released; otherwise, false.

IsMousePositionLocked

Gets the value indicating if the mouse position is currently locked or not.

public bool IsMousePositionLocked { get; }

Property Value

bool

KeyEvents

Key events that happened since the last frame

public IReadOnlyList<KeyEvent> KeyEvents { get; }

Property Value

IReadOnlyList<KeyEvent>

Keyboard

Gets the first keyboard device, or null if there is none

public IKeyboardDevice Keyboard { get; }

Property Value

IKeyboardDevice

Keyboards

Gets the collection of connected keyboard inputs

public IReadOnlyList<IKeyboardDevice> Keyboards { get; }

Property Value

IReadOnlyList<IKeyboardDevice>

LastPointerDevice

Device that is responsible for setting the current MouseDelta and MousePosition

public IPointerDevice LastPointerDevice { get; }

Property Value

IPointerDevice

Mouse

Gets the first mouse pointer device, or null if there is none

public IMouseDevice Mouse { get; }

Property Value

IMouseDevice

MouseDelta

Mouse delta in normalized coordinate space

public Vector2 MouseDelta { get; }

Property Value

Vector2

MousePosition

The mouse position in normalized coordinates.

public Vector2 MousePosition { get; set; }

Property Value

Vector2

MouseWheelDelta

The delta value of the mouse wheel button since last frame.

public float MouseWheelDelta { get; }

Property Value

float

Orientation

Gets the reference to the orientation sensor. The orientation sensor measures orientation of device in the world.

public IOrientationSensor Orientation { get; }

Property Value

IOrientationSensor

Pointer

Gets the first pointer device, or null if there is none

public IPointerDevice Pointer { get; }

Property Value

IPointerDevice

PointerEvents

Pointer events that happened since the last frame

public IReadOnlyList<PointerEvent> PointerEvents { get; }

Property Value

IReadOnlyList<PointerEvent>

Pointers

Gets the collection of connected pointing devices (mouses, touchpads, etc)

public IReadOnlyList<IPointerDevice> Pointers { get; }

Property Value

IReadOnlyList<IPointerDevice>

PressedButtons

The mouse buttons that have been pressed since the last frame

public IReadOnlySet<MouseButton> PressedButtons { get; }

Property Value

IReadOnlySet<MouseButton>

PressedKeys

The keys that have been pressed since the last frame

public IReadOnlySet<Keys> PressedKeys { get; }

Property Value

IReadOnlySet<Keys>

ReleasedButtons

The mouse buttons that have been released since the last frame

public IReadOnlySet<MouseButton> ReleasedButtons { get; }

Property Value

IReadOnlySet<MouseButton>

ReleasedKeys

The keys that have been released since the last frame

public IReadOnlySet<Keys> ReleasedKeys { get; }

Property Value

IReadOnlySet<Keys>

Sensors

Gets the collection of connected sensor devices

public IReadOnlyList<ISensorDevice> Sensors { get; }

Property Value

IReadOnlyList<ISensorDevice>

Sources

Input sources

public TrackingCollection<IInputSource> Sources { get; }

Property Value

TrackingCollection<IInputSource>

TextInput

First device that supports text input, or null if there is none

public ITextInputDevice TextInput { get; }

Property Value

ITextInputDevice

UseRawInput

Should raw input be used on windows

public bool UseRawInput { get; set; }

Property Value

bool

UserAcceleration

Gets the reference to the user acceleration sensor. The user acceleration sensor measures the acceleration produce by the user on the device (no gravity).

public IUserAccelerationSensor UserAcceleration { get; }

Property Value

IUserAccelerationSensor

VirtualButtonConfigSet

Gets or sets the configuration for virtual buttons.

public VirtualButtonConfigSet VirtualButtonConfigSet { get; set; }

Property Value

VirtualButtonConfigSet

The current binding.

Methods

AddListener(IInputEventListener)

Registers an object that listens for certain types of events using the specialized versions of IInputEventListener<TEventType>

public void AddListener(IInputEventListener listener)

Parameters

listener IInputEventListener

The listener to register

Destroy()

Disposes of object resources.

protected override void Destroy()

GetFreeGamePadIndex(IGamePadDevice)

Suggests an index that is unused for a given IGamePadDevice

public int GetFreeGamePadIndex(IGamePadDevice gamePad)

Parameters

gamePad IGamePadDevice

The gamepad to find an index for

Returns

int

The unused gamepad index

GetGamePadByIndex(int)

Gets the first gamepad with a specific index

public IGamePadDevice GetGamePadByIndex(int gamePadIndex)

Parameters

gamePadIndex int

The index of the gamepad

Returns

IGamePadDevice

The gamepad, or null if no gamepad has this index

Exceptions

IndexOutOfRangeException

When gamePadIndex is less than 0

GetGamePadsByIndex(int)

Gets all the gamepads with a specific index

public IEnumerable<IGamePadDevice> GetGamePadsByIndex(int gamePadIndex)

Parameters

gamePadIndex int

The index of the gamepad

Returns

IEnumerable<IGamePadDevice>

The gamepads, or null if no gamepad has this index

Exceptions

IndexOutOfRangeException

When gamePadIndex is less than 0

GetVirtualButton(int, object)

Gets a binding value for the specified name and the specified config extract from the current VirtualButtonConfigSet.

public virtual float GetVirtualButton(int configIndex, object bindingName)

Parameters

configIndex int

An index to a VirtualButtonConfig stored in the VirtualButtonConfigSet

bindingName object

Name of the binding.

Returns

float

The value of the binding.

Initialize(GameContext)

public void Initialize(GameContext gameContext)

Parameters

gameContext GameContext

IsKeyDown(Keys)

Determines whether the specified key is being pressed down.

public bool IsKeyDown(Keys key)

Parameters

key Keys

The key.

Returns

bool

true if the specified key is being pressed down; otherwise, false.

IsKeyPressed(Keys)

Determines whether the specified key is pressed since the previous update.

public bool IsKeyPressed(Keys key)

Parameters

key Keys

The key.

Returns

bool

true if the specified key is pressed; otherwise, false.

IsKeyReleased(Keys)

Determines whether the specified key is released since the previous update.

public bool IsKeyReleased(Keys key)

Parameters

key Keys

The key.

Returns

bool

true if the specified key is released; otherwise, false.

IsMouseButtonDown(MouseButton)

Determines whether the specified mouse button is being pressed down.

public bool IsMouseButtonDown(MouseButton mouseButton)

Parameters

mouseButton MouseButton

The mouse button.

Returns

bool

true if the specified mouse button is being pressed down; otherwise, false.

IsMouseButtonPressed(MouseButton)

Determines whether the specified mouse button is pressed since the previous update.

public bool IsMouseButtonPressed(MouseButton mouseButton)

Parameters

mouseButton MouseButton

The mouse button.

Returns

bool

true if the specified mouse button is pressed since the previous update; otherwise, false.

IsMouseButtonReleased(MouseButton)

Determines whether the specified mouse button is released.

public bool IsMouseButtonReleased(MouseButton mouseButton)

Parameters

mouseButton MouseButton

The mouse button.

Returns

bool

true if the specified mouse button is released; otherwise, false.

LockMousePosition(bool)

Lock the mouse's position and hides it until the next call to UnlockMousePosition().

public void LockMousePosition(bool forceCenter = false)

Parameters

forceCenter bool

If true will make sure that the mouse cursor position moves to the center of the client window

Remarks

This function has no effects on devices that does not have mouse

Pause()

Pause all input sources.

public void Pause()

PoolInputEvent(InputEvent)

Inserts any registered event back into it's InputEventPool<TEventType>.

public void PoolInputEvent(InputEvent inputEvent)

Parameters

inputEvent InputEvent

The event to insert into it's event pool

ProcessEvent(KeyEvent)

Processes a new input event

public void ProcessEvent(KeyEvent inputEvent)

Parameters

inputEvent KeyEvent

the input event

ProcessEvent(MouseWheelEvent)

Processes a new input event

public void ProcessEvent(MouseWheelEvent inputEvent)

Parameters

inputEvent MouseWheelEvent

the input event

ProcessEvent(PointerEvent)

Processes a new input event

public void ProcessEvent(PointerEvent inputEvent)

Parameters

inputEvent PointerEvent

the input event

RegisterEventType<TEventType>()

Registers an input event type to process

public void RegisterEventType<TEventType>() where TEventType : InputEvent, new()

Type Parameters

TEventType

The event type to process

RemoveListener(IInputEventListener)

Removes a previously registered event listener

public void RemoveListener(IInputEventListener listener)

Parameters

listener IInputEventListener

The listener to remove

ResetSources()

Resets the Sources collection back to it's default values

public void ResetSources()

Resume()

Resume all input sources.

public void Resume()

Scan()

Rescans all input devices in order to query new device connected. See remarks.

public void Scan()

Remarks

This method could take several milliseconds and should be used at specific time in a game where performance is not crucial (pause, configuration screen...etc.)

TransformPosition(Size2F, RectangleF, Vector2)

Helper method to transform mouse and pointer event positions to sub rectangles

public static Vector2 TransformPosition(Size2F fromSize, RectangleF destinationRectangle, Vector2 screenCoordinates)

Parameters

fromSize Size2F

the size of the source rectangle

destinationRectangle RectangleF

The destination viewport rectangle

screenCoordinates Vector2

The normalized screen coordinates

Returns

Vector2

UnlockMousePosition()

Unlock the mouse's position previously locked by calling LockMousePosition(bool) and restore the mouse visibility.

public void UnlockMousePosition()

Remarks

This function has no effects on devices that does not have mouse

Update(GameTime)

public void Update(GameTime gameTime)

Parameters

gameTime GameTime

Events

DeviceAdded

Raised when a device was added to the system

public event EventHandler<DeviceChangedEventArgs> DeviceAdded

Event Type

EventHandler<DeviceChangedEventArgs>

DeviceRemoved

Raised when a device was removed from the system

public event EventHandler<DeviceChangedEventArgs> DeviceRemoved

Event Type

EventHandler<DeviceChangedEventArgs>

PreUpdateInput

Raised before new input is sent to their respective event listeners

public event EventHandler<InputPreUpdateEventArgs> PreUpdateInput

Event Type

EventHandler<InputPreUpdateEventArgs>