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
- .MousePosition readonly : Vector3
- .MouseDelta readonly : Vector3
Methods
- :IsKeyDown(key: string) : bool
- :IsMouseButtonDown(button: int) : bool
- :GetBuiltinButton(name: string) : BuiltinButton?
Events
- .InputBegan : Event (input: InputInfo)
- .InputEnded : Event (input: InputInfo)
- .InputChanged : Event (input: InputInfo)
- .BuiltinButtonPressed : Event (name: string)
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:
| Field | Type | Notes |
|---|---|---|
Key | string? | Keyboard key name, if any |
Button | int? | Mouse button index, if any |
Position | Vector3 | Screen position for pointer or touch |
Delta | Vector3 | Movement delta for pointer or touch |
Touch | bool | true for touch input |
BuiltinButton
Read-only view of a built-in mobile control.
