InputManager Class
Namespace: Stride.InputAssembly: 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
Name | Description | |
---|---|---|
Constructors | ||
InputManager() | Initializes a new instance of the InputManager class. |
|
Fields | ||
GameControllerAxisDeadZone | The deadzone amount applied to all game controller axes |
|
Properties | ||
AbsoluteMouseDelta | Mouse movement in device coordinates |
|
AbsoluteMousePosition | Mouse coordinates in device coordinates |
|
Accelerometer | Gets the reference to the accelerometer sensor. The accelerometer measures all the acceleration forces applied on the device. |
|
Compass | Gets the reference to the compass sensor. The compass measures the angle between the device top and the north. |
|
DefaultGamePad | Gets the first gamepad that was added to the device |
|
DownButtons | The mouse buttons that are down |
|
DownKeys | The keys that are down |
|
Events | All input events that happened since the last frame |
|
GameControllerCount | Gets the number of game controllers connected. |
|
GameControllers | Gets the collection of connected game controllers |
|
GamePadCount | Gets the number of gamepads connected. |
|
GamePads | Gets the collection of connected gamepads |
|
GestureEvents | Gets the collection of gesture events since the previous updates. |
|
Gestures | List of the gestures to recognize. |
|
Gravity | Gets the reference to the gravity sensor. The gravity sensor measures the gravity vector applied to the device. |
|
Gyroscope | Gets the reference to the gyroscope sensor. The gyroscope measures the rotation speed of the device. |
|
HasDownKeys | Determines whether one or more keys are down |
|
HasDownMouseButtons | Determines whether one or more of the mouse buttons are down |
|
HasGameController | Gets a value indicating whether game controllers are available. |
|
HasGamePad | Gets a value indicating whether gamepads are available. |
|
HasKeyboard | Gets a value indicating whether the keyboard is available. |
|
HasMouse | Gets a value indicating whether the mouse is available. |
|
HasPointer | Gets a value indicating whether pointer device is available. |
|
HasPressedKeys | Determines whether one or more keys are pressed |
|
HasPressedMouseButtons | Determines whether one or more of the mouse buttons are pressed |
|
HasReleasedKeys | Determines whether one or more keys are released |
|
HasReleasedMouseButtons | Determines whether one or more of the mouse buttons are released |
|
IsMousePositionLocked | Gets the value indicating if the mouse position is currently locked or not. |
|
Keyboard | Gets the first keyboard device, or null if there is none |
|
Keyboards | Gets the collection of connected keyboard inputs |
|
KeyEvents | Key events that happened since the last frame |
|
LastPointerDevice | Device that is responsible for setting the current MouseDelta and MousePosition |
|
Mouse | Gets the first mouse pointer device, or null if there is none |
|
MouseDelta | Mouse delta in normalized coordinate space |
|
MousePosition | The mouse position in normalized coordinates. |
|
MouseWheelDelta | The delta value of the mouse wheel button since last frame. |
|
Orientation | Gets the reference to the orientation sensor. The orientation sensor measures orientation of device in the world. |
|
Pointer | Gets the first pointer device, or null if there is none |
|
PointerEvents | Pointer events that happened since the last frame |
|
Pointers | Gets the collection of connected pointing devices (mouses, touchpads, etc) |
|
PressedButtons | The mouse buttons that have been pressed since the last frame |
|
PressedKeys | The keys that have been pressed since the last frame |
|
ReleasedButtons | The mouse buttons that have been released since the last frame |
|
ReleasedKeys | The keys that have been released since the last frame |
|
Sensors | Gets the collection of connected sensor devices |
|
Sources | Input sources |
|
TextInput | First device that supports text input, or null if there is none |
|
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). |
|
UseRawInput | Should raw input be used on windows |
|
VirtualButtonConfigSet | Gets or sets the configuration for virtual buttons. |
|
Methods | ||
AddListener(IInputEventListener) | Registers an object that listens for certain types of events using the specialized versions of IInputEventListener<TEventType> |
|
Destroy() | ||
GetFreeGamePadIndex(IGamePadDevice) | Suggests an index that is unused for a given IGamePadDevice |
|
GetGamePadByIndex(Int32) | Gets the first gamepad with a specific index |
|
GetGamePadsByIndex(Int32) | Gets all the gamepads with a specific index |
|
GetVirtualButton(Int32, Object) | Gets a binding value for the specified name and the specified config extract from the current VirtualButtonConfigSet. |
|
Initialize(GameContext) | ||
IsKeyDown(Keys) | Determines whether the specified key is being pressed down. |
|
IsKeyPressed(Keys) | Determines whether the specified key is pressed since the previous update. |
|
IsKeyReleased(Keys) | Determines whether the specified key is released since the previous update. |
|
IsMouseButtonDown(MouseButton) | Determines whether the specified mouse button is being pressed down. |
|
IsMouseButtonPressed(MouseButton) | Determines whether the specified mouse button is pressed since the previous update. |
|
IsMouseButtonReleased(MouseButton) | Determines whether the specified mouse button is released. |
|
LockMousePosition(Boolean) | Lock the mouse's position and hides it until the next call to UnlockMousePosition(). |
|
Pause() | Pause all input sources. |
|
PoolInputEvent(InputEvent) | Inserts any registered event back into it's InputEventPool<TEventType>. |
|
ProcessEvent(KeyEvent) | ||
ProcessEvent(MouseWheelEvent) | ||
ProcessEvent(PointerEvent) | ||
RegisterEventType<TEventType>() | Registers an input event type to process |
|
RemoveListener(IInputEventListener) | Removes a previously registered event listener |
|
ResetSources() | Resets the Sources collection back to it's default values |
|
Resume() | Resume all input sources. |
|
Scan() | Rescans all input devices in order to query new device connected. See remarks. |
|
TransformPosition(Size2F, RectangleF, Vector2) | Helper method to transform mouse and pointer event positions to sub rectangles |
|
UnlockMousePosition() | Unlock the mouse's position previously locked by calling LockMousePosition(Boolean) and restore the mouse visibility. |
|
Update(GameTime) | ||
Events | ||
DeviceAdded | Raised when a device was added to the system |
|
DeviceRemoved | Raised when a device was removed from the system |
|
PreUpdateInput | Raised before new input is sent to their respective event listeners |
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
Type | Description |
---|---|
System.Single |
Properties
AbsoluteMouseDelta
Mouse movement in device coordinates
public Vector2 AbsoluteMouseDelta { get; }
Property Value
Type | Description |
---|---|
Vector2 |
AbsoluteMousePosition
Mouse coordinates in device coordinates
public Vector2 AbsoluteMousePosition { get; }
Property Value
Type | Description |
---|---|
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
Type | Description |
---|---|
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
Type | Description |
---|---|
ICompassSensor |
DefaultGamePad
Gets the first gamepad that was added to the device
public IGamePadDevice DefaultGamePad { get; }
Property Value
Type | Description |
---|---|
IGamePadDevice |
DownButtons
The mouse buttons that are down
public IReadOnlySet<MouseButton> DownButtons { get; }
Property Value
Type | Description |
---|---|
IReadOnlySet<MouseButton> |
DownKeys
The keys that are down
public IReadOnlySet<Keys> DownKeys { get; }
Property Value
Type | Description |
---|---|
IReadOnlySet<Keys> |
Events
All input events that happened since the last frame
public IReadOnlyList<InputEvent> Events { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<InputEvent> |
GameControllerCount
Gets the number of game controllers connected.
public int GameControllerCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The number of game controllers connected. |
GameControllers
Gets the collection of connected game controllers
public IReadOnlyList<IGameControllerDevice> GameControllers { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IGameControllerDevice> |
GamePadCount
Gets the number of gamepads connected.
public int GamePadCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The number of gamepads connected. |
GamePads
Gets the collection of connected gamepads
public IReadOnlyList<IGamePadDevice> GamePads { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IGamePadDevice> |
GestureEvents
Gets the collection of gesture events since the previous updates.
public IReadOnlyList<GestureEvent> GestureEvents { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<GestureEvent> | The gesture events. |
Gestures
List of the gestures to recognize.
public TrackingCollection<GestureConfig> Gestures { get; }
Property Value
Type | Description |
---|---|
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
Type | Description |
---|---|
IGravitySensor |
Gyroscope
Gets the reference to the gyroscope sensor. The gyroscope measures the rotation speed of the device.
public IGyroscopeSensor Gyroscope { get; }
Property Value
Type | Description |
---|---|
IGyroscopeSensor |
HasDownKeys
Determines whether one or more keys are down
public bool HasDownKeys { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasDownMouseButtons
Determines whether one or more of the mouse buttons are down
public bool HasDownMouseButtons { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasGameController
Gets a value indicating whether game controllers are available.
public bool HasGameController { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasGamePad
Gets a value indicating whether gamepads are available.
public bool HasGamePad { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasKeyboard
Gets a value indicating whether the keyboard is available.
public bool HasKeyboard { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasMouse
Gets a value indicating whether the mouse is available.
public bool HasMouse { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasPointer
Gets a value indicating whether pointer device is available.
public bool HasPointer { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasPressedKeys
Determines whether one or more keys are pressed
public bool HasPressedKeys { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasPressedMouseButtons
Determines whether one or more of the mouse buttons are pressed
public bool HasPressedMouseButtons { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasReleasedKeys
Determines whether one or more keys are released
public bool HasReleasedKeys { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
HasReleasedMouseButtons
Determines whether one or more of the mouse buttons are released
public bool HasReleasedMouseButtons { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsMousePositionLocked
Gets the value indicating if the mouse position is currently locked or not.
public bool IsMousePositionLocked { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Keyboard
Gets the first keyboard device, or null if there is none
public IKeyboardDevice Keyboard { get; }
Property Value
Type | Description |
---|---|
IKeyboardDevice |
Keyboards
Gets the collection of connected keyboard inputs
public IReadOnlyList<IKeyboardDevice> Keyboards { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IKeyboardDevice> |
KeyEvents
Key events that happened since the last frame
public IReadOnlyList<KeyEvent> KeyEvents { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<KeyEvent> |
LastPointerDevice
Device that is responsible for setting the current MouseDelta and MousePosition
public IPointerDevice LastPointerDevice { get; }
Property Value
Type | Description |
---|---|
IPointerDevice |
Mouse
Gets the first mouse pointer device, or null if there is none
public IMouseDevice Mouse { get; }
Property Value
Type | Description |
---|---|
IMouseDevice |
MouseDelta
Mouse delta in normalized coordinate space
public Vector2 MouseDelta { get; }
Property Value
Type | Description |
---|---|
Vector2 |
MousePosition
The mouse position in normalized coordinates.
public Vector2 MousePosition { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
MouseWheelDelta
The delta value of the mouse wheel button since last frame.
public float MouseWheelDelta { get; }
Property Value
Type | Description |
---|---|
System.Single |
Orientation
Gets the reference to the orientation sensor. The orientation sensor measures orientation of device in the world.
public IOrientationSensor Orientation { get; }
Property Value
Type | Description |
---|---|
IOrientationSensor |
Pointer
Gets the first pointer device, or null if there is none
public IPointerDevice Pointer { get; }
Property Value
Type | Description |
---|---|
IPointerDevice |
PointerEvents
Pointer events that happened since the last frame
public IReadOnlyList<PointerEvent> PointerEvents { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<PointerEvent> |
Pointers
Gets the collection of connected pointing devices (mouses, touchpads, etc)
public IReadOnlyList<IPointerDevice> Pointers { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IPointerDevice> |
PressedButtons
The mouse buttons that have been pressed since the last frame
public IReadOnlySet<MouseButton> PressedButtons { get; }
Property Value
Type | Description |
---|---|
IReadOnlySet<MouseButton> |
PressedKeys
The keys that have been pressed since the last frame
public IReadOnlySet<Keys> PressedKeys { get; }
Property Value
Type | Description |
---|---|
IReadOnlySet<Keys> |
ReleasedButtons
The mouse buttons that have been released since the last frame
public IReadOnlySet<MouseButton> ReleasedButtons { get; }
Property Value
Type | Description |
---|---|
IReadOnlySet<MouseButton> |
ReleasedKeys
The keys that have been released since the last frame
public IReadOnlySet<Keys> ReleasedKeys { get; }
Property Value
Type | Description |
---|---|
IReadOnlySet<Keys> |
Sensors
Gets the collection of connected sensor devices
public IReadOnlyList<ISensorDevice> Sensors { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<ISensorDevice> |
Sources
Input sources
public TrackingCollection<IInputSource> Sources { get; }
Property Value
Type | Description |
---|---|
TrackingCollection<IInputSource> |
TextInput
First device that supports text input, or null if there is none
public ITextInputDevice TextInput { get; }
Property Value
Type | Description |
---|---|
ITextInputDevice |
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
Type | Description |
---|---|
IUserAccelerationSensor |
UseRawInput
Should raw input be used on windows
public bool UseRawInput { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
VirtualButtonConfigSet
Gets or sets the configuration for virtual buttons.
public VirtualButtonConfigSet VirtualButtonConfigSet { get; set; }
Property Value
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
IInputEventListener | listener | The listener to register |
Destroy()
protected override void Destroy()
Overrides
GetFreeGamePadIndex(IGamePadDevice)
Suggests an index that is unused for a given IGamePadDevice
public int GetFreeGamePadIndex(IGamePadDevice gamePad)
Parameters
Type | Name | Description |
---|---|---|
IGamePadDevice | gamePad | The gamepad to find an index for |
Returns
Type | Description |
---|---|
System.Int32 | The unused gamepad index |
GetGamePadByIndex(Int32)
Gets the first gamepad with a specific index
public IGamePadDevice GetGamePadByIndex(int gamePadIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | gamePadIndex | The index of the gamepad |
Returns
Type | Description |
---|---|
IGamePadDevice | The gamepad, or null if no gamepad has this index |
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | When |
GetGamePadsByIndex(Int32)
Gets all the gamepads with a specific index
public IEnumerable<IGamePadDevice> GetGamePadsByIndex(int gamePadIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | gamePadIndex | The index of the gamepad |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IGamePadDevice> | The gamepads, or null if no gamepad has this index |
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | When |
GetVirtualButton(Int32, 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
Type | Name | Description |
---|---|---|
System.Int32 | configIndex | An index to a VirtualButtonConfig stored in the VirtualButtonConfigSet |
System.Object | bindingName | Name of the binding. |
Returns
Type | Description |
---|---|
System.Single | The value of the binding. |
Initialize(GameContext)
public void Initialize(GameContext gameContext)
Parameters
Type | Name | Description |
---|---|---|
GameContext | gameContext |
IsKeyDown(Keys)
Determines whether the specified key is being pressed down.
public bool IsKeyDown(Keys key)
Parameters
Type | Name | Description |
---|---|---|
Keys | key | The key. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsKeyPressed(Keys)
Determines whether the specified key is pressed since the previous update.
public bool IsKeyPressed(Keys key)
Parameters
Type | Name | Description |
---|---|---|
Keys | key | The key. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsKeyReleased(Keys)
Determines whether the specified key is released since the previous update.
public bool IsKeyReleased(Keys key)
Parameters
Type | Name | Description |
---|---|---|
Keys | key | The key. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsMouseButtonDown(MouseButton)
Determines whether the specified mouse button is being pressed down.
public bool IsMouseButtonDown(MouseButton mouseButton)
Parameters
Type | Name | Description |
---|---|---|
MouseButton | mouseButton | The mouse button. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsMouseButtonPressed(MouseButton)
Determines whether the specified mouse button is pressed since the previous update.
public bool IsMouseButtonPressed(MouseButton mouseButton)
Parameters
Type | Name | Description |
---|---|---|
MouseButton | mouseButton | The mouse button. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsMouseButtonReleased(MouseButton)
Determines whether the specified mouse button is released.
public bool IsMouseButtonReleased(MouseButton mouseButton)
Parameters
Type | Name | Description |
---|---|---|
MouseButton | mouseButton | The mouse button. |
Returns
Type | Description |
---|---|
System.Boolean |
|
LockMousePosition(Boolean)
Lock the mouse's position and hides it until the next call to UnlockMousePosition().
public void LockMousePosition(bool forceCenter = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | forceCenter | 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
Type | Name | Description |
---|---|---|
InputEvent | inputEvent | The event to insert into it's event pool |
ProcessEvent(KeyEvent)
public void ProcessEvent(KeyEvent inputEvent)
Parameters
Type | Name | Description |
---|---|---|
KeyEvent | inputEvent |
ProcessEvent(MouseWheelEvent)
public void ProcessEvent(MouseWheelEvent inputEvent)
Parameters
Type | Name | Description |
---|---|---|
MouseWheelEvent | inputEvent |
ProcessEvent(PointerEvent)
public void ProcessEvent(PointerEvent inputEvent)
Parameters
Type | Name | Description |
---|---|---|
PointerEvent | inputEvent |
RegisterEventType<TEventType>()
Registers an input event type to process
public void RegisterEventType<TEventType>()
where TEventType : InputEvent, new()
Type Parameters
Name | Description |
---|---|
TEventType | The event type to process |
RemoveListener(IInputEventListener)
Removes a previously registered event listener
public void RemoveListener(IInputEventListener listener)
Parameters
Type | Name | Description |
---|---|---|
IInputEventListener | listener | 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
Type | Name | Description |
---|---|---|
Size2F | fromSize | the size of the source rectangle |
RectangleF | destinationRectangle | The destination viewport rectangle |
Vector2 | screenCoordinates | The normalized screen coordinates |
Returns
Type | Description |
---|---|
Vector2 |
UnlockMousePosition()
Unlock the mouse's position previously locked by calling LockMousePosition(Boolean) 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
Type | Name | Description |
---|---|---|
GameTime | gameTime |
Events
DeviceAdded
Raised when a device was added to the system
public event EventHandler<DeviceChangedEventArgs> DeviceAdded
Event Type
Type | Description |
---|---|
System.EventHandler<DeviceChangedEventArgs> |
DeviceRemoved
Raised when a device was removed from the system
public event EventHandler<DeviceChangedEventArgs> DeviceRemoved
Event Type
Type | Description |
---|---|
System.EventHandler<DeviceChangedEventArgs> |
PreUpdateInput
Raised before new input is sent to their respective event listeners
public event EventHandler<InputPreUpdateEventArgs> PreUpdateInput
Event Type
Type | Description |
---|---|
System.EventHandler<InputPreUpdateEventArgs> |