docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Mouse

    An input device representing a mouse.

    Inheritance
    object
    InputControl
    InputDevice
    Pointer
    Mouse
    Implements
    IInputStateCallbackReceiver
    Inherited Members
    Pointer.position
    Pointer.delta
    Pointer.radius
    Pointer.pressure
    Pointer.press
    Pointer.displayIndex
    InputDevice.InvalidDeviceId
    InputDevice.description
    InputDevice.enabled
    InputDevice.canRunInBackground
    InputDevice.added
    InputDevice.remote
    InputDevice.native
    InputDevice.updateBeforeRender
    InputDevice.deviceId
    InputDevice.lastUpdateTime
    InputDevice.wasUpdatedThisFrame
    InputDevice.allControls
    InputDevice.valueType
    InputDevice.valueSizeInBytes
    InputDevice.ReadValueFromBufferAsObject(void*, int)
    InputDevice.ReadValueFromStateAsObject(void*)
    InputDevice.ReadValueFromStateIntoBuffer(void*, void*, int)
    InputDevice.CompareValue(void*, void*)
    InputDevice.OnConfigurationChanged()
    InputDevice.ExecuteCommand<TCommand>(ref TCommand)
    InputDevice.ExecuteCommand(InputDeviceCommand*)
    InputControl.name
    InputControl.displayName
    InputControl.shortDisplayName
    InputControl.path
    InputControl.layout
    InputControl.variants
    InputControl.device
    InputControl.parent
    InputControl.children
    InputControl.usages
    InputControl.aliases
    InputControl.stateBlock
    InputControl.noisy
    InputControl.synthetic
    InputControl.this[string]
    InputControl.magnitude
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(void*)
    InputControl.WriteValueFromBufferIntoState(void*, int, void*)
    InputControl.WriteValueFromObjectIntoState(object, void*)
    InputControl.TryGetChildControl(string)
    InputControl.TryGetChildControl<TControl>(string)
    InputControl.GetChildControl(string)
    InputControl.GetChildControl<TControl>(string)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.RefreshConfiguration()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    InputControl.optimizedControlDataType
    InputControl.CalculateOptimizedControlDataType()
    InputControl.ApplyParameterChanges()
    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
    ButtonControl
    Remarks

    On Windows, this corresponds to RI_MOUSE_BUTTON_4.

    See Also
    Pointer

    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
    IntegerControl
    See Also
    Pointer

    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 MakeCurrent().

    See Also
    Pointer

    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
    ButtonControl
    Remarks

    On Windows, this corresponds to RI_MOUSE_BUTTON_5.

    See Also
    Pointer

    leftButton

    Control representing left button of a Mouse device.

    Declaration
    public ButtonControl leftButton { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    See Also
    Pointer

    middleButton

    Control representing middle button of a Mouse device.

    Declaration
    public ButtonControl middleButton { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    See Also
    Pointer

    rightButton

    Control representing right button of a Mouse device.

    Declaration
    public ButtonControl rightButton { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    See Also
    Pointer

    scroll

    Control representing horizontal and vertical scroll wheels of a Mouse device.

    Declaration
    public DeltaControl scroll { get; protected set; }
    Property Value
    Type Description
    DeltaControl
    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
    Pointer

    Methods

    FinishSetup()

    Perform final initialization tasks after the control hierarchy has been put into place.

    Declaration
    protected override void FinishSetup()
    Overrides
    Pointer.FinishSetup()
    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
    Pointer

    MakeCurrent()

    Called when the mouse becomes the current mouse.

    Declaration
    public override void MakeCurrent()
    Overrides
    Pointer.MakeCurrent()
    Remarks

    This is called automatically by the system when there is input on a connected mouse.

    See Also
    Pointer

    OnAdded()

    Called when the mouse is added to the system.

    Declaration
    protected override void OnAdded()
    Overrides
    InputDevice.OnAdded()
    See Also
    Pointer

    OnNextUpdate()

    Implements OnNextUpdate() for the mouse.

    Declaration
    protected void OnNextUpdate()
    See Also
    Pointer

    OnRemoved()

    Called when the device is removed from the system.

    Declaration
    protected override void OnRemoved()
    Overrides
    Pointer.OnRemoved()
    See Also
    Pointer

    OnStateEvent(InputEventPtr)

    Implements OnStateEvent(InputEventPtr) for the mouse.

    Declaration
    protected void OnStateEvent(InputEventPtr eventPtr)
    Parameters
    Type Name Description
    InputEventPtr eventPtr

    Pointer to an InputEvent. Makes it easier to work with InputEvents and hides the unsafe operations necessary to work with them.

    See Also
    Pointer

    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.

    See Also
    Pointer

    Implements

    IInputStateCallbackReceiver

    Extension Methods

    InputControlExtensions.CheckStateIsAtDefault(InputControl)
    InputControlExtensions.CheckStateIsAtDefault(InputControl, void*, void*)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*, void*)
    InputControlExtensions.CompareStateIgnoringNoise(InputControl, void*)
    InputControlExtensions.FindControlsRecursive<TControl>(InputControl, IList<TControl>, Func<TControl, bool>)
    InputControlExtensions.FindInParentChain<TControl>(InputControl)
    InputControlExtensions.GetStatePtrFromStateEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInState(InputControl, void*)
    InputControlExtensions.IsActuated(InputControl, float)
    InputControlExtensions.IsPressed(InputControl, float)
    InputControlExtensions.ReadDefaultValueAsObject(InputControl)
    InputControlExtensions.ReadValueAsObject(InputControl)
    InputControlExtensions.ReadValueFromEventAsObject(InputControl, InputEventPtr)
    InputControlExtensions.ReadValueIntoBuffer(InputControl, void*, int)
    InputControlExtensions.ResetToDefaultStateInEvent(InputControl, InputEventPtr)
    InputControlExtensions.WriteValueFromObjectIntoEvent(InputControl, InputEventPtr, object)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState(InputControl, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl, TValue, void*)
    InputControlExtensions.CopyState(InputDevice, void*, int)
    InputControlExtensions.CopyState<TState>(InputDevice, out TState)

    See Also

    Pointer
    In This Article
    • Properties
      • backButton
      • clickCount
      • current
      • forwardButton
      • leftButton
      • middleButton
      • rightButton
      • scroll
    • Methods
      • FinishSetup()
      • MakeCurrent()
      • OnAdded()
      • OnNextUpdate()
      • OnRemoved()
      • OnStateEvent(InputEventPtr)
      • WarpCursorPosition(Vector2)
    • Implements
    • Extension Methods
    • See Also
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)