Luduvo Contents
Theme
On this page

Input

reads the keyboard and mouse state of the local client, and the camera ray under the cursor

Methods

5 members Access: shared

ButtonDown(button: number) -> boolean

whether a mouse button is down

Parameters
NameTypeDescription
buttonnumber0 left, 1 right, 2 middle.
returnsboolean—
ButtonPressed(button: number) -> boolean

whether a mouse button was pressed this frame

Parameters
NameTypeDescription
buttonnumber0 left, 1 right, 2 middle.
returnsboolean—
KeyDown(keyCode: number) -> boolean

whether a key is down

Parameters
NameTypeDescription
keyCodenumberVirtual key code (Windows VK / browser keyCode numbering), 87 for W. game.Input.Key names them, e.g. game.Input.Key.W.
returnsboolean—
KeyPressed(keyCode: number) -> boolean

whether a key was pressed this frame

Parameters
NameTypeDescription
keyCodenumberVirtual key code (Windows VK / browser keyCode numbering), 87 for W. game.Input.Key names them, e.g. game.Input.Key.W.
returnsboolean—
PointerRay() -> (vector?, vector?)

camera ray through the cursor

Polling Keyboard State and Cursor Raycasting

Lifecycle: Client

Key state and the pointer ray are polled on demand rather than delivered as events.

Luau
if game.Input.KeyDown(game.Input.Key.W) then -- 87, the virtual key code	-- Advance player forwardendlocal origin, direction = game.Input.PointerRay()if origin and direction then	local hit = game.Physics.Raycast(origin, direction, 100)	if hit then		print("Hovered entity:", tostring(hit.Entity))	endend