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
Name Type Description button number 0 left, 1 right, 2 middle. returns boolean — - ButtonPressed
(button: number) -> boolean whether a mouse button was pressed this frame
Parameters
Name Type Description button number 0 left, 1 right, 2 middle. returns boolean — - KeyDown
(keyCode: number) -> boolean whether a key is down
Parameters
Name Type Description keyCode number Virtual key code (Windows VK / browser keyCode numbering), 87 for W. game.Input.Key names them, e.g. game.Input.Key.W. returns boolean — - KeyPressed
(keyCode: number) -> boolean whether a key was pressed this frame
Parameters
Name Type Description keyCode number Virtual key code (Windows VK / browser keyCode numbering), 87 for W. game.Input.Key names them, e.g. game.Input.Key.W. returns boolean — - 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