Want a special badge and 30 bux? Make some PolyWorld! Content and post it in the Creations forum!
Dark mode is incomplete! Please report any issues to the Discord.

InputModule

LocalScripts Not creatable

InputModule reads mouse, keyboard, and touch input on the client.
Available as the global InputModule in LocalScripts.

Built-in mobile buttons (jump, and other engine HUD controls) keep priority.
Scripts cannot place overlapping UI that steals those presses.


Overview

Properties

Methods

Events


API

Properties

MousePosition

MousePosition readonly : Vector3
Current mouse position in screen pixels.
Z is unused and stays 0.

MouseDelta

MouseDelta readonly : Vector3
Mouse movement since the last frame, in pixels.

Methods

IsKeyDown

IsKeyDown(key: string) : bool
Returns true while the named key is held.
Use simple names such as "W", "Space", "LeftShift".

IsMouseButtonDown

IsMouseButtonDown(button: int) : bool
Returns true while a mouse button is held.
0 is left, 1 is right, 2 is middle.

GetBuiltinButton

GetBuiltinButton(name: string) : BuiltinButton?
Returns a built-in mobile control by name, such as "Jump".
These controls always keep input priority over custom UI.

Events

InputBegan

InputBegan : Event (input: InputInfo)
Fires when a key, mouse button, or touch press starts.

InputModule.InputBegan:Connect(function(input)
    if input.Key == "E" then
        FireServer("interact")
    end
end)

InputEnded

InputEnded : Event (input: InputInfo)
Fires when a key, mouse button, or touch press ends.

InputChanged

InputChanged : Event (input: InputInfo)
Fires when pointer or touch position changes.

BuiltinButtonPressed

BuiltinButtonPressed : Event (name: string)
Fires when a built-in mobile button is pressed.
Custom on-screen buttons must not cover these controls.


InputInfo

Fields passed to input events:

FieldTypeNotes
Keystring?Keyboard key name, if any
Buttonint?Mouse button index, if any
PositionVector3Screen position for pointer or touch
DeltaVector3Movement delta for pointer or touch
Touchbooltrue for touch input

BuiltinButton

Read-only view of a built-in mobile control.

FieldTypeNotes
NamestringButton id, such as "Jump"
PositionVector3Screen position (X, Y). Built-in priority still wins over custom UI
SizeVector3Screen size
IsDownboolWhether the button is currently pressed