Virtual cursor
How virtual mouse and keyboard input reaches Roblox, and the on-screen cursor that shows it.
The cursor is drawn by Acedia using a Demo UI script that uses the input functions.
Cursor states
The cursor follows the same rules as a desktop pointer. It decides from what is under it, using the engine's own GUI hit test, so a hidden, clipped or covered GUI never counts.
| Cursor | Shown when |
|---|---|
| Arrow | Nothing interactive is under the cursor. |
| I-beam | A TextBox is under the cursor. |
| Hand | A GuiButton (TextButton, ImageButton) is under the cursor, or a mouse button is pressed or was just clicked. |
| Move | A mouse button is held while the cursor moves, as in a drag. |
Coordinates
Virtual mouse positions are Roblox viewport pixels, the same space as GetMouseLocation(). That space counts the topbar, which a GUI's AbsolutePosition does not, so add the GUI inset when aiming at a GUI:
local inset = game:GetService("GuiService"):GetGuiInset()
local function aim(gui)
local pos, size = gui.AbsolutePosition, gui.AbsoluteSize
mousemoveabs(pos.X + size.X / 2 + inset.X, pos.Y + size.Y / 2 + inset.Y)
endmousemoverel adds to the last virtual position, not to the real pointer, so start with a mousemoveabs call.
Example
Hovers a text box and types into it, presses a button, then drags along a slider:
local inset = game:GetService("GuiService"):GetGuiInset()
local function aim(gui)
local pos, size = gui.AbsolutePosition, gui.AbsoluteSize
mousemoveabs(pos.X + size.X / 2 + inset.X, pos.Y + size.Y / 2 + inset.Y)
task.wait(0.5)
end
aim(textBox) -- I-beam
mouse1click() -- focuses the box
for _, vk in { 0x48, 0x49 } do
keytap(vk) -- types "hi"
end
aim(confirmButton) -- hand
mouse1click() -- squash and bounce
aim(sliderKnob)
mouse1press()
for i = 1, 30 do
mousemoverel(6, 0) -- move cursor while held
task.wait()
end
mouse1release()Limits
- The hit test asks CoreGui first, then PlayerGui.
