PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

MouseEnabled

UserInputService

bool

This property describes whether the user’s device has a mouse available. This property is true when the user’s device has an available mouse, and false when it does not.

local UserInputService = game:GetService("UserInputService")

if (UserInputService.MouseEnabled) then
    print("The user's device has an available mouse!")
else
    print("The user's device does not have an available mouse!")
end

It is important to check this before using UserInputService mouse functions such as UserInputService/GetMouseLocation.

As UserInputService is client-side only, this property can only be used in a LocalScript.

See also

  • UserInputService/MouseBehavior
  • UserInputService/MouseDeltaSensitivity
  • UserInputService/MouseIconEnabled
  • UserInputService/GetMouseLocation
  • UserInputService/GetMouseDelta
  • UserInputService/GetMouseButtonsPressed


Code Samples


Create a Binoculars Script

This example creates a binoculars script that decreases the player’s Camera/FieldOfView|FieldOfView and UserInputService/MouseDeltaSensitivity|MouseDeltaSensitivity when a player with a UserInputService/MouseEnabled|MouseEnabled left mouse clicks. The script also points the player’s Camera towards the DataType/Vector3|Vector3 world position of the mouse click determined by the Mouse|Mouse’s Mouse/Hit|Mouse.Hit.p property.

When the player left mouse clicks again, the player’s camera reverts back to the a custom Enum/CameraType|CameraType with the same field of view and Camera/CFrame|CFrame as before the player zoomed in with the script.

While the player uses the binoculars, the script locks the player’s mouse to the center of the screen by setting the player’s UserInputType/MouseBehavior|MouseBehavior to LockCenter. The player’s camera moves when the player moves their mouse according to the InputObject/Delta|InputObject.Delta property passed by UserInputService/InputChanged|InputChanged indicating the mouse’s DataType/Vector2|Vector2 change in screen position.

In order for this example to work as expected, it should be placed in a LocalScript.