Mouse Support | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Mouse Support

    Mice are represented by the Mouse device layout which is implemented by the Mouse class. Mice are based on the Pointer layout.

    The last used or last added mouse can be queried with Mouse.current.

        var mouse = Mouse.current;
    

    NOTES:

    • We do not yet support separating input from multiple mice at the platform level.
    • We do not yet support identifying the current display a mouse is on.

    Controls

    Additional to the controls inherited from Pointer, Mouse devices implement the following controls:

    Control Type Description
    leftButton ButtonControl The left mouse button. Same as the inherited Pointer.press.
    rightButton ButtonControl The right mouse button.
    middleButton ButtonControl The middle mouse button.
    forwardButton
    ButtonControl Used for further mouse buttons where applicable.
    backButton ButtonControl Used for further mouse buttons where applicable.
    clickCount IntegerControl A control which lets you read the number of consecutive clicks the last mouse click belonged to, as reported by the OS. This can be used to distinguish double- or multi-clicks.
    scroll Vector2Control The input from the mouse scrolling control expressed as a delta in pixels since the last frame. Can come from a physics scroll wheel, or from gestures on a touch pad.

    Cursor Warping

    On desktop platforms (Windows, Mac, Linux, and UWP), the mouse cursor can be moved from code. Note that this will move the system's actual mouse cursor, not just Unity's internally stored mouse position. This means that the user will visibly see the cursor jumping to a different position. This is usually considered a bad UI practice, and it is advisable to only do this when the cursor is hidden (see the Cursor API).

    To move the cursor to a different position, use Mouse.WarpCursorPosition. The coordinates are in Unity screen coordinates just like Mouse.position.

        Mouse.current.WarpCursorPosition(new Vector2(123, 234));
    

    NOTE: If the cursor is locked, warping the mouse position will only temporarily take effect. Unity will reset the cursor to the center of the window every frame.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023