A clean mouse object using up-to-date input APIs. Only works on the client, and there should only be one instance of this object running at one point in time.
The mouse object can be configured in the Configuration module. This will allow you to disable things such as the Target property and the RbxTargetFilter object, and change values such as the length of the ray being cast for the CFrame and Target properties.
Example usage:
local Mouse = require(script.RbxMouse)
Mouse.TargetFilter:Add(workspace.Part)
Mouse.Icon:Set(12345678)
local leftMouseButton = Mouse.Button[1]
leftMouseButton.Down:Connect(function()
print("Left mouse button pressed!")
end
local rightMouseButton = Mouse.Button.Right
rightMouseButton.Click:Connect(function(timeSpentDown))
print("Right mouse button clicked!")
end
Mouse.Move:Connect(function(newPosition)
print("Left mouse button is down =", leftMouseButton.IsDown)
print("Current mouse target is", Mouse.Target)
end
This module returns a RbxMouse
object which can be used similar to the official Mouse
object.
Object that holds 3 RbxMouseButton
objects, one for each of the 3 buttons on a mouse.
They can be indexed either by their number (1, 2, 3) or their name/position (Left, Right, Middle).
Mouse.Button[1]
Mouse.Button.Left
Mouse.Button[2]
Mouse.Button.Right
Mouse.Button[3]
Mouse.Button.Middle
RbxMouseIcon
object for the mouse.
RbxTargetFilter
for the mouse. Will throw an exception if target is disabled in configuration.
This Mouse
object has a lot of similar properties.
The 2D position of the mouse.
The 3D position and direction of the mouse.
The BasePart the mouse is hovering over. Will throw an exception if target is disabled in configuration.
Fires every time the mouse is moved. The position of the mouse is passed to the callback function.
Hides the mouse icon. Only needs to be called once.
Shows the mouse icon. Only needs to be called once.
Disconnects all input listeners without removing your connections. Useful if you want to put the Mouse's properties into a static state, or if you want to stop listening for Mouse input.
Reconnects all input listeners.
A RbxMouseButton
objects represents one of the buttons on a mouse.
Whether the button is being pressed or not.
Fired when the button is pressed.
Fired when the button is released.
Fired when the button is released if the time the button was spent down was smaller than or equal to the click threshold (defaults to 0.5 seconds, can be configured in the configuration module).
Forces the button to be pressed. The button will still be considered released when the user stops pressing the button.
Forces the button to be released. The button will still be considered pressed when the user presses the button.
A RbxMouseIcon
object is responsible for the mouse icon.
Shows the mouse icon. Only needs to be called once.
Hides the mouse icon. Only needs to be called once.
Sets the mouse icon to an image asset path. If AssetId
is an int, it will convert it into a valid path before setting it. Call it with nil or an empty string to reset the icon.
Returns the current mouse icon asset ID. Returns an empty string if it has not been set.
A RbxTargetFilter
objects is responsible for managing the objects in the mouse's target filter. A target filter is an array that cannot hold more than one reference to the same Instance
at the same time.
Sets the target filter to an array (overwriting the old target filter). If the Object
argument is an Instance
, it will create an array and insert the Instance
into the array. If there are duplicate references, only one will be used.
Returns the array of objects in the target filter.
Adds an object into the target filter. If this will cause duplicate references, it will not be added.
Removes an instance from the target filter.