Class Mouse
An input device representing a mouse.
Implements
Inherited Members
Namespace: UnityEngine .InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public class Mouse : Pointer, IInputStateCallbackReceiver
Remarks
Adds a scroll wheel and a typical 5-button setup with a left, middle, right, forward and backward button.
To control cursor display and behavior, use Cursor.
Examples
using UnityEngine;
using UnityEngine.InputSystem;
public class ExampleScript : MonoBehaviour
{
void Update()
{
// If there is a current mouse and the left button was pressed
if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame)
{
// handle left mouse button being pressed
}
}
}
Properties
backButton
Control representing the first side button, often labeled/used as "back", of a Mouse device.
Declaration
public ButtonControl backButton { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Remarks
On Windows, this corresponds to RI_MOUSE_BUTTON_4
.
See Also
clickCount
Control representing the number of times any of the mouse buttons has been clicked in succession within the system-defined click time threshold.
Declaration
public IntegerControl clickCount { get; protected set; }
Property Value
Type | Description |
---|---|
Integer |
See Also
current
The mouse that was added or updated last or null if there is no mouse connected to the system.
Declaration
public static Mouse current { get; }
Property Value
Type | Description |
---|---|
Mouse |
Remarks
To set a mouse device as current, use Make
See Also
forwardButton
Control representing the second side button, often labeled/used as "forward", of a Mouse device.
Declaration
public ButtonControl forwardButton { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Remarks
On Windows, this corresponds to RI_MOUSE_BUTTON_5
.
See Also
leftButton
Control representing left button of a Mouse device.
Declaration
public ButtonControl leftButton { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
See Also
middleButton
Control representing middle button of a Mouse device.
Declaration
public ButtonControl middleButton { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
See Also
rightButton
Control representing right button of a Mouse device.
Declaration
public ButtonControl rightButton { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
See Also
scroll
Control representing horizontal and vertical scroll wheels of a Mouse device.
Declaration
public DeltaControl scroll { get; protected set; }
Property Value
Type | Description |
---|---|
Delta |
Remarks
The x
component corresponds to the horizontal scroll wheel, the
y
component to the vertical scroll wheel. Most mice do not have
horizontal scroll wheels and will thus only see activity on y
.
See Also
Methods
FinishSetup()
Perform final initialization tasks after the control hierarchy has been put into place.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
Examples
public class MyDevice : InputDevice
{
public ButtonControl button { get; private set; }
public AxisControl axis { get; private set; }
protected override void OnFinishSetup()
{
// Cache controls in getters.
button = GetChildControl("button");
axis = GetChildControl("axis");
}
}
See Also
MakeCurrent()
Called when the mouse becomes the current mouse.
Declaration
public override void MakeCurrent()
Overrides
Remarks
This is called automatically by the system when there is input on a connected mouse.
See Also
OnAdded()
Called when the mouse is added to the system.
Declaration
protected override void OnAdded()
Overrides
See Also
OnNextUpdate()
Implements On
Declaration
protected void OnNextUpdate()
See Also
OnRemoved()
Called when the device is removed from the system.
Declaration
protected override void OnRemoved()
Overrides
See Also
OnStateEvent(InputEventPtr)
Implements On
Declaration
protected void OnStateEvent(InputEventPtr eventPtr)
Parameters
Type | Name | Description |
---|---|---|
Input |
eventPtr | Pointer to an Input |
See Also
WarpCursorPosition(Vector2)
Move the operating system's mouse cursor by performing a device command in a similar way to DeviceIoControl on Windows and ioctl on UNIX-like systems.
Declaration
public void WarpCursorPosition(Vector2 position)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position | New position in player window space. |
Remarks
The position property will not update immediately but rather will update in the next input update.