PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Mouse

Show deprecated

Mouse

Show deprecated

The Mouse object is the code interface for the computer mouse.

How to get the Mouse?

A Mouse object is not createable, but can be obtained using the Player/GetMouse, Tool/Equipped. The PluginMouse object, which inherits from Mouse can be created using the Plugin Plugin/GetMouse function.

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer -- from a LocalScript
local mouse = Player:GetMouse()
Tool.Equipped:Connect(function(mouse)
	-- got mouse
end)

Mouse alternatives

There is a degree of overlap between the functionality offered by ContextActionService, UserInputService and the Mouse object.

Mouse, by and large, has been superseded by UserInputService which offers wider additional functionality for interacting with the mouse as well as other input types. For example:

  • UserInputService supports other inputs such as key presses and mobile inputs whereas Mouse does not
  • UserInputService includes additional mouse features such as UserInputService/MouseBehavior and UserInputService/MouseDeltaSensitivity

In most cases developers are advised to use the new UserInputService. However the Mouse object remains supported for a number of reasons.

  • Mouse existed long before UserInputService and a large number of places and gear items are dependent on it
  • The PluginMouse object is still used by plugins accessing the mouse
  • The mouse object is embedded into Tools and is easier to pick up for new developers

Properties

CFrame

Hit

[ReadOnly] [NotReplicated]

The DataType/CFrame of the mouse’s position in 3D space

Content

Icon

The content ID of the image used as the Mouse's icon.

CFrame

Origin

[ReadOnly] [NotReplicated]

A DataType/CFrame positioned at the Workspace/CurrentCamera and oriented toward the Mouse's 3D position.

BasePart

Target

[ReadOnly] [NotReplicated]

The object in 3D space the Mouse|mouse is pointing to

Instance

TargetFilter

Determines an object (and its descendants) to be ignored when determining Mouse/Hit and Mouse/Target

NormalId

TargetSurface

[ReadOnly] [NotReplicated]

Indicates the Enum/NormalId of the BasePart surface at which the mouse is pointing

Ray

UnitRay

[ReadOnly] [NotReplicated]

A DataType/Ray directed towards the Mouse's world position, originating from the Workspace/CurrentCamera|Camera's world position

int

ViewSizeX

[ReadOnly] [NotReplicated]

Describes the width of the game window in pixels

int

ViewSizeY

[ReadOnly] [NotReplicated]

Describes the height of the game window in pixels

int

X

[ReadOnly] [NotReplicated]

Describes the X (horizontal) component of the mouse’s position on the screen

int

Y

[ReadOnly] [NotReplicated]

Describes the Y (vertical) component of the mouse’s screen position

Functions

Events

RBXScriptSignal

Button1Down ( )

Fired when the left mouse button is pressed.

RBXScriptSignal

Button1Up ( )

Fires when the left mouse button is released.

RBXScriptSignal

Button2Down ( )

Fires when the right mouse button is pressed.

RBXScriptSignal

Button2Up ( )

Fired when the right mouse button is released

RBXScriptSignal

Idle ( )

Fired during every heartbeat that the mouse isn’t being passed to another mouse event.

RBXScriptSignal

Move ( )

Fired when the mouse is moved.

RBXScriptSignal

WheelBackward ( )

Fires when the mouse wheel is scrolled backwards

RBXScriptSignal

WheelForward ( )

Fires when the mouse wheel is scrolled forwards.