Class InputManager
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
Properties
AbsoluteMouseDelta
Mouse movement in device coordinates
public Vector2 AbsoluteMouseDelta { get; }
Property Value
AbsoluteMousePosition
Mouse coordinates in device coordinates
public Vector2 AbsoluteMousePosition { get; }
Property Value
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
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
DefaultGamePad
Gets the first gamepad that was added to the device
public IGamePadDevice DefaultGamePad { get; }
Property Value
DownButtons
The mouse buttons that are down
public IReadOnlySet<MouseButton> DownButtons { get; }
Property Value
DownKeys
The keys that are down
public IReadOnlySet<Keys> DownKeys { get; }
Property Value
Events
All input events that happened since the last frame
public IReadOnlyList<InputEvent> Events { get; }
Property Value
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
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
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
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
Gyroscope
Gets the reference to the gyroscope sensor. The gyroscope measures the rotation speed of the device.
public IGyroscopeSensor Gyroscope { get; }
Property Value
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
KeyEvents
Key events that happened since the last frame
public IReadOnlyList<KeyEvent> KeyEvents { get; }
Property Value
Keyboard
Gets the first keyboard device, or null if there is none
public IKeyboardDevice Keyboard { get; }
Property Value
Keyboards
Gets the collection of connected keyboard inputs
public IReadOnlyList<IKeyboardDevice> Keyboards { get; }
Property Value
LastPointerDevice
Device that is responsible for setting the current MouseDelta and MousePosition
public IPointerDevice LastPointerDevice { get; }
Property Value
Mouse
Gets the first mouse pointer device, or null if there is none
public IMouseDevice Mouse { get; }
Property Value
MouseDelta
Mouse delta in normalized coordinate space
public Vector2 MouseDelta { get; }
Property Value
MousePosition
The mouse position in normalized coordinates.
public Vector2 MousePosition { get; set; }
Property Value
MouseWheelDelta
The delta value of the mouse wheel button since last frame.
public float MouseWheelDelta { get; }
Property Value
Orientation
Gets the reference to the orientation sensor. The orientation sensor measures orientation of device in the world.
public IOrientationSensor Orientation { get; }
Property Value
Pointer
Gets the first pointer device, or null if there is none
public IPointerDevice Pointer { get; }
Property Value
PointerEvents
Pointer events that happened since the last frame
public IReadOnlyList<PointerEvent> PointerEvents { get; }
Property Value
Pointers
Gets the collection of connected pointing devices (mouses, touchpads, etc)
public IReadOnlyList<IPointerDevice> Pointers { get; }
Property Value
PressedButtons
The mouse buttons that have been pressed since the last frame
public IReadOnlySet<MouseButton> PressedButtons { get; }
Property Value
PressedKeys
The keys that have been pressed since the last frame
public IReadOnlySet<Keys> PressedKeys { get; }
Property Value
ReleasedButtons
The mouse buttons that have been released since the last frame
public IReadOnlySet<MouseButton> ReleasedButtons { get; }
Property Value
ReleasedKeys
The keys that have been released since the last frame
public IReadOnlySet<Keys> ReleasedKeys { get; }
Property Value
Sensors
Gets the collection of connected sensor devices
public IReadOnlyList<ISensorDevice> Sensors { get; }
Property Value
Sources
Input sources
public TrackingCollection<IInputSource> Sources { get; }
Property Value
TextInput
First device that supports text input, or null if there is none
public ITextInputDevice TextInput { get; }
Property Value
UseRawInput
Should raw input be used on windows
public bool UseRawInput { get; set; }
Property Value
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
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
IInputEventListenerThe 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
IGamePadDeviceThe 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
intThe 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
intThe 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.
[Obsolete("This method is obsolete. Call GetVirtualButtonValue instead.")]
public virtual float GetVirtualButton(int configIndex, object bindingName)
Parameters
configIndex
intAn index to a VirtualButtonConfig stored in the VirtualButtonConfigSet.
bindingName
objectName of the binding.
Returns
- float
The value of the binding.
GetVirtualButtonValue(int, object)
Gets a binding value for the specified name and the specified config extract from the current VirtualButtonConfigSet.
public virtual float GetVirtualButtonValue(int configIndex, object bindingName)
Parameters
configIndex
intAn index to a VirtualButtonConfig stored in the VirtualButtonConfigSet.
bindingName
objectName 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
KeysThe 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
KeysThe 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
KeysThe 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
MouseButtonThe 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
MouseButtonThe 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
MouseButtonThe mouse button.
Returns
- bool
true
if the specified mouse button is released; otherwise,false
.
IsVirtualButtonDown(int, object)
Determines whether the specified binding in the specified config in the current VirtualButtonConfigSet is currently pressed down.
public virtual bool IsVirtualButtonDown(int configIndex, object bindingName)
Parameters
configIndex
intAn index to a VirtualButtonConfig stored in the VirtualButtonConfigSet.
bindingName
objectName of the binding.
Returns
- bool
true
if the binding is currently pressed down; otherwise,false
.
IsVirtualButtonPressed(int, object)
Determines whether the specified binding in the specified config in the current VirtualButtonConfigSet was pressed since the previous Update.
public virtual bool IsVirtualButtonPressed(int configIndex, object bindingName)
Parameters
configIndex
intAn index to a VirtualButtonConfig stored in the VirtualButtonConfigSet.
bindingName
objectName of the binding.
Returns
- bool
true
if the binding was pressed; otherwise,false
.
IsVirtualButtonReleased(int, object)
Determines whether the specified binding in the specified config in the current VirtualButtonConfigSet was released since the previous Update.
public virtual bool IsVirtualButtonReleased(int configIndex, object bindingName)
Parameters
configIndex
intAn index to a VirtualButtonConfig stored in the VirtualButtonConfigSet.
bindingName
objectName of the binding.
Returns
- bool
true
if the binding was 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
boolIf 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
InputEventThe event to insert into it's event pool
ProcessEvent(KeyEvent)
Processes a new input event
public void ProcessEvent(KeyEvent inputEvent)
Parameters
inputEvent
KeyEventthe input event
ProcessEvent(MouseWheelEvent)
Processes a new input event
public void ProcessEvent(MouseWheelEvent inputEvent)
Parameters
inputEvent
MouseWheelEventthe input event
ProcessEvent(PointerEvent)
Processes a new input event
public void ProcessEvent(PointerEvent inputEvent)
Parameters
inputEvent
PointerEventthe 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
IInputEventListenerThe 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
Size2Fthe size of the source rectangle
destinationRectangle
RectangleFThe destination viewport rectangle
screenCoordinates
Vector2The normalized screen coordinates
Returns
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
DeviceRemoved
Raised when a device was removed from the system
public event EventHandler<DeviceChangedEventArgs> DeviceRemoved
Event Type
PreUpdateInput
Raised before new input is sent to their respective event listeners
public event EventHandler<InputPreUpdateEventArgs> PreUpdateInput