Input¶
System · Input · server and client scripts
Input reads the local player's keyboard, mouse, gamepad, touch, and VR controller input and sets the cursor and UI selection. It works in client scripts only.
Every pressable input has one InputName string: keys such as "E", "Enter", "LeftShift", and "ArrowUp", mouse buttons ("MouseLeft", "MouseRight", "MouseMiddle", "MouseX1", "MouseX2"), wheel turns ("WheelUp", "WheelDown", "WheelLeft", "WheelRight"), gamepad buttons ("ButtonA", "LeftTrigger", "RightTrigger"), VR buttons ("VRTriggerRight"), and "Touch". Analog thumbsticks have no InputName; read them with Input.Stick or bind them with InputBinding.Stick (see Input entities).
Opening the escape menu or a host modal releases every held input: WasReleased returns true and Released(input, false) fires on that frame. An input still held when the menu closes stays up until the player releases and presses it again.
IsDown¶
IsDown returns true while the input named input is held down, unless the escape menu, engine UI, or a Sink input context took it.
Example
Errors (1)
| Error | When |
|---|---|
IsDown can only be called from a client script |
Called from a server script. |
WasPressed¶
WasPressed returns true on the frame the input named input goes down, and false after. Wheel turns and taps within one frame return true on that frame.
Example
Errors (1)
| Error | When |
|---|---|
WasPressed can only be called from a client script |
Called from a server script. |
WasReleased¶
WasReleased returns true on the frame the input named input goes up, or on the frame the escape menu or a Sink context starts taking it.
Example
Errors (1)
| Error | When |
|---|---|
WasReleased can only be called from a client script |
Called from a server script. |
GetHeld¶
GetHeld returns the InputName list of inputs currently held down and not taken by the escape menu, engine UI, or a Sink context.
Example
Errors (1)
| Error | When |
|---|---|
GetHeld can only be called from a client script |
Called from a server script. |
Pressed¶
Pressed fires with (input, processed) when an input goes down. processed is true when the escape menu, a host modal, a focused text box, or engine UI took the press. Inputs taken by a Sink context do not fire Pressed.
Example
Errors (1)
| Error | When |
|---|---|
Pressed can only be written from a client script |
Written from a server script. |
Released¶
Released fires with (input, processed) when an input goes up, with the same processed value as its Pressed. Inputs taken by a Sink context do not fire Released.
Example
Errors (1)
| Error | When |
|---|---|
Released can only be written from a client script |
Written from a server script. |
MoveCharacter¶
MoveCharacter controls whether built-in character movement and jump controls read player input. Set it to false when a custom vehicle, menu, or text capture takes over movement.
Default true
Errors (1)
| Error | When |
|---|---|
MoveCharacter can only be written from a client script |
Written from a server script. |
Capture¶
CaptureText¶
CaptureText turns on the operating system's text input when true and sends committed UTF-8 text to TextInput while the escape menu and console are closed. While a text box has focus, the text box receives the typed text and TextInput does not fire.
Default false
Errors (1)
| Error | When |
|---|---|
CaptureText can only be written from a client script |
Written from a server script. |
TextCursor¶
TextCursor sets the IME candidate window position in UI points from the top-left corner of the game view while CaptureText is true, or nil to clear it. A focused text box sets its own IME position while it has focus.
Default nil
Errors (1)
| Error | When |
|---|---|
TextCursor can only be written from a client script |
Written from a server script. |
TextInput¶
TextInput fires with text, the UTF-8 text the player committed since the last frame, while CaptureText is true.
Example
Errors (1)
| Error | When |
|---|---|
TextInput can only be written from a client script |
Written from a server script. |
Cursor¶
MouseCursor¶
MouseCursor is the cursor shape over the 3D world and over UI elements whose Cursor is "Auto", using a string cursor name such as "Auto", "Crosshair", "Pointer", or "Hidden".
Default "Auto"
Errors (1)
| Error | When |
|---|---|
MouseCursor can only be written from a client script |
Written from a server script. |
SetCustomCursor¶
SetCustomCursor shows an image in place of one cursor shape (other than "Auto" and "Hidden"), with an optional click point in image pixels.
Example
Errors (1)
| Error | When |
|---|---|
SetCustomCursor can only be called from a client script |
Called from a server script. |
Device¶
PreferredInput¶
PreferredInput is the device type the player used last ("KeyboardAndMouse", "Gamepad", "Touch", or "VR").
Default "KeyboardAndMouse"
Errors (1)
| Error | When |
|---|---|
PreferredInput can only be written from a client script |
Written from a server script. |
PreferredInputChanged¶
PreferredInputChanged fires with the new PreferredInput when the player switches between keyboard and mouse, gamepad, touch, and VR.
Example
Errors (1)
| Error | When |
|---|---|
PreferredInputChanged can only be written from a client script |
Written from a server script. |
Gamepad¶
Stick¶
Stick returns the 2D deflection of "LeftStick" or "RightStick" as a Vector2 with radial deadzone applied. deadzone is a number in 0..0.95 (default 0.2). Returns Vector2.Zero while the escape menu is open or a Sink context takes the stick.
Example
Errors (1)
| Error | When |
|---|---|
Stick can only be called from a client script |
Called from a server script. |
Trigger¶
Trigger returns the analog pull in 0..1 of "LeftTrigger" or "RightTrigger" after deadzone rescaling. deadzone is a number in 0..0.95 (default 0.1). Returns 0 while the escape menu is open or a Sink context takes the trigger.
Example
Errors (1)
| Error | When |
|---|---|
Trigger can only be called from a client script |
Called from a server script. |
Vibrate¶
Vibrate pulses the last active gamepad's low-frequency and high-frequency motors with (low, high, seconds). low and high are in 0..1, and seconds is in 0..60. Opening the escape menu or losing window focus stops rumble.
Errors (1)
| Error | When |
|---|---|
Vibrate can only be called from a client script |
Called from a server script. |
Pointer¶
Selected¶
Selected is the UI element that has the gamepad and keyboard selection, or nil.
Default nil
Example
-- Client script.
local screen = World.Spawn({ UIRoot = true })
screen.Parent = World.Viewport.Screen
local play = World.Spawn({
Box = {},
Panel = {},
UITextSource = { Text = "Play" },
Button = true,
})
play.Parent = screen
play:On(Component.Button.Clicked, function()
print("play")
end)
Input.Selected = play
Errors (1)
| Error | When |
|---|---|
Selected can only be written from a client script |
Written from a server script. |
MouseBehavior¶
MouseBehavior is "Default" or "LockCenter".
Default "Default"
Errors (1)
| Error | When |
|---|---|
MouseBehavior can only be written from a client script |
Written from a server script. |
MousePosition¶
MousePosition is the cursor position in UI points from the top-left corner of the game view.
Errors (1)
| Error | When |
|---|---|
MousePosition can only be written from a client script |
Written from a server script. |
MouseDelta¶
MouseDelta is the cursor movement since the last script update, in UI points.
Errors (1)
| Error | When |
|---|---|
MouseDelta can only be written from a client script |
Written from a server script. |
LookDelta¶
LookDelta is the mouse movement since the last script update, in the units the built-in camera turns by.
Errors (1)
| Error | When |
|---|---|
LookDelta can only be written from a client script |
Written from a server script. |
Scroll¶
Scroll is the mouse wheel movement since the last script update, positive up.
Errors (1)
| Error | When |
|---|---|
Scroll can only be written from a client script |
Written from a server script. |
RotationType¶
RotationType is "MovementRelative" or "CameraRelative", controlling whether the character turns toward its movement direction or faces the camera's horizontal direction.
Default "MovementRelative"
Errors (1)
| Error | When |
|---|---|
RotationType can only be written from a client script |
Written from a server script. |
Touch¶
Touches¶
Touches returns the active unprocessed touches ordered by Id, up to five simultaneous fingers. Each Touch has Id, Position, StartPosition, and Delta in UI points.
Touches do not emulate mouse buttons or move MousePosition. "Touch" is held while any unprocessed finger is down.
Example
Errors (1)
| Error | When |
|---|---|
Touches can only be called from a client script |
Called from a server script. |
TouchBegan¶
TouchBegan fires with (touch, processed) when a finger touches down. processed is true when engine UI or a Button took the touch.
Example
Errors (1)
| Error | When |
|---|---|
TouchBegan can only be written from a client script |
Written from a server script. |
TouchMoved¶
TouchMoved fires once per frame with (touch, processed) for each active finger that moved, with touch.Delta equal to the frame's movement.
Example
Errors (1)
| Error | When |
|---|---|
TouchMoved can only be written from a client script |
Written from a server script. |
TouchEnded¶
TouchEnded fires with (touch, processed) when a finger lifts, cancels, or is released by the escape menu opening.
Example
Errors (1)
| Error | When |
|---|---|
TouchEnded can only be written from a client script |
Written from a server script. |