A simple module for much better mouse events on Roblox
In your script, call initMouseOverlay(screenGui)
, or call it without any parameters to automatically generate a ScreenGui. Then, use the mouseEvents
function as such:
function mouseEvents(item: GuiObject, button: 1 | 2, events: { Enter?, Up?, Down?, Leave?, Move?, Click?, DoubleClick? })
If you are using Roact, you may also call bindToRoact
. Example:
BetterMouse.initMouseOverlay()
BetterMouse.bindToRoact(game:GetService("ReplicatedStorage"):WaitForChild("Roact"))
This will replace the Mouse* events with BetterMouse alternatives. To use the raw Mouse* events, prefix them with raw. So if you want to use the raw MouseButton1Down event rather than the BetterMouse alternative, use [Roact.Event.RawMouseButton1Down]
Roblox MouseUp does not fire if the user moves their mouse outside of the GuiObject's bounding box while keeping the mouse down. The MouseLeave and MouseEnter functions are also not reliable. These issues have both been fixed in this module.