Class Mouse
An input device representing a mouse.
Inherited Members
Namespace: UnityEngine.InputSystem
Syntax
public class Mouse : Pointer, IInputStateCallbackReceiver
Remarks
Adds a scroll wheel and a typical 3-button setup with a left, middle, and right button.
To control cursor display and behavior, use Cursor.
Properties
backButton
The first side button, often labeled/used as "back".
Declaration
public ButtonControl backButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the back button on the mouse. |
Remarks
On Windows, this corresponds to RI_MOUSE_BUTTON_4
.
clickCount
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 |
---|---|
IntegerControl | Control representing the mouse click count. |
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 |
See Also
forwardButton
The second side button, often labeled/used as "forward".
Declaration
public ButtonControl forwardButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the forward button on the mouse. |
Remarks
On Windows, this corresponds to RI_MOUSE_BUTTON_5
.
leftButton
The left mouse button.
Declaration
public ButtonControl leftButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the left mouse button. |
middleButton
The middle mouse button.
Declaration
public ButtonControl middleButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the middle mouse button. |
rightButton
The right mouse button.
Declaration
public ButtonControl rightButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the right mouse button. |
scroll
The horizontal and vertical scroll wheels.
Declaration
public DeltaControl scroll { get; protected set; }
Property Value
Type | Description |
---|---|
DeltaControl | Control representing the mouse scroll wheels. |
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
.
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.
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");
}
}
MakeCurrent()
Called when the mouse becomes the current mouse.
Declaration
public override void MakeCurrent()
Overrides
OnAdded()
Called when the mouse is added to the system.
Declaration
protected override void OnAdded()
Overrides
OnNextUpdate()
Implements OnNextUpdate() for the mouse.
Declaration
protected void OnNextUpdate()
OnRemoved()
Called when the device is removed from the system.
Declaration
protected override void OnRemoved()
Overrides
OnStateEvent(InputEventPtr)
Implements OnStateEvent(InputEventPtr) for the mouse.
Declaration
protected void OnStateEvent(InputEventPtr eventPtr)
Parameters
Type | Name | Description |
---|---|---|
InputEventPtr | eventPtr |
WarpCursorPosition(Vector2)
Move the operating system's mouse cursor.
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.
Explicit Interface Implementations
IInputStateCallbackReceiver.OnNextUpdate()
Declaration
void IInputStateCallbackReceiver.OnNextUpdate()
Implements
IInputStateCallbackReceiver.OnStateEvent(InputEventPtr)
Declaration
void IInputStateCallbackReceiver.OnStateEvent(InputEventPtr eventPtr)
Parameters
Type | Name | Description |
---|---|---|
InputEventPtr | eventPtr |