InputService
Client input from keyboards, pointers, touchscreens and gamepads.
- Service
game:GetService("InputService")- Inherits
- Instance
- Replication
- Never
Behavior
InputService reports what the player is physically doing. Its Began,
Changed and Ended signals cover the life of an input and pass an
InputObject describing it.
Narrow on the input type before reading fields such as KeyCode or Position.
For an action that needs several bindings, use BindAction so the mapping has
one name and can later be removed with UnbindAction.
Summary
Whether the service instance is included when its containing hierarchy is cloned or saved.
The analog input magnitude below which gamepad movement is ignored.
Whether keyboard input is available.
The device that most recently produced input, useful for choosing control hints.
The pointer locking mode.
Whether mouse input is available.
Whether the pointer icon is displayed.
The instance name.
The on-screen keyboard's position in pixels.
The on-screen keyboard's size in pixels.
Whether the on-screen keyboard is visible.
The service's parent instance.
The input-device category currently preferred by the player.
Whether touch input is available.
BindAction(actionName: string, functionToBind: (actionName: string, inputState: EnumItem, inputObject: InputObject) -> EnumItem?, createTouchButton: boolean?, args: ...EnumItem): ()serial onlyBinds a named action to one or more input types.
BindActionAtPriority(actionName: string, functionToBind: (actionName: string, inputState: EnumItem, inputObject: InputObject) -> EnumItem?, createTouchButton: boolean, priority: number | EnumItem, args: ...EnumItem): ()serial onlyBinds a named action at an explicit priority.
Creates a named ActionContext with its own action bindings, priority, and modal behavior.
Returns the touch button created for the named action, or nil if no button exists.
Returns information about the registered action bindings.
Returns the gamepad identifiers currently connected.
Returns the input devices currently available to the player.
Returns this instance if it is an ExecutionGroup.
Returns the current axis value for the gamepad and key code.
Returns whether the specified gamepad is connected.
Returns the device name of a connected gamepad, or nil if it is unavailable.
Returns the inputs that are currently held down.
Tests whether a particular input is currently held.
Returns whether the specified gamepad button is pressed.
Sets the description of a named action's touch button.
Sets the image of a named action's touch button.
Sets the position of a named action's touch button.
Sets the title of a named action's touch button.
Remaps a gamepad button.
Sets gamepad vibration strengths and an optional duration in seconds.
Removes one named action binding.
Removes all action bindings owned by the service.
Fires when an input starts, such as a key going down or a button being pressed.
Fires when an ongoing input changes, such as pointer movement or a thumbstick axis changing.
Fires when an input stops.
Fires when a gamepad connects.
Fires when a gamepad disconnects.
Fires when the preferred input-device category changes.
Fires when a touch contact ends.
Fires when a touch contact moves.
Fires when a touch contact begins.
Fires when a touch tap is recognized.
Properties
Archivable
InputService.Archivable: boolean = trueWhether the service instance is included when its containing hierarchy is cloned
or saved. The default is true.
GamepadDeadZone
InputService.GamepadDeadZone: numberThe analog input magnitude below which gamepad movement is ignored.
KeyboardEnabled
InputService.KeyboardEnabled: booleanWhether keyboard input is available.
LastDevice
InputService.LastDevice: EnumItemThe device that most recently produced input, useful for choosing control hints.
MouseBehavior
InputService.MouseBehavior: EnumItemThe pointer locking mode.
MouseEnabled
InputService.MouseEnabled: booleanWhether mouse input is available.
MouseIconEnabled
InputService.MouseIconEnabled: booleanWhether the pointer icon is displayed.
Name
InputService.Name: string = "InputService"The instance name. The default is "InputService".
OnScreenKeyboardPosition
InputService.OnScreenKeyboardPosition: Vector2The on-screen keyboard's position in pixels.
OnScreenKeyboardSize
InputService.OnScreenKeyboardSize: Vector2The on-screen keyboard's size in pixels.
OnScreenKeyboardVisible
InputService.OnScreenKeyboardVisible: booleanWhether the on-screen keyboard is visible.
Parent
InputService.Parent: Instance? = nilThe service's parent instance. The default is nil.
PreferredInput
InputService.PreferredInput: EnumItemThe input-device category currently preferred by the player.
TouchEnabled
InputService.TouchEnabled: booleanWhether touch input is available.
Methods
BindAction
InputService:BindAction(actionName: string, functionToBind: (actionName: string, inputState: EnumItem, inputObject: InputObject) -> EnumItem?, createTouchButton: boolean?, args: ...EnumItem): ()Binds a named action to one or more input types. Keep the handler small and unbind it when the action is no longer available.
BindActionAtPriority
InputService:BindActionAtPriority(actionName: string, functionToBind: (actionName: string, inputState: EnumItem, inputObject: InputObject) -> EnumItem?, createTouchButton: boolean, priority: number | EnumItem, args: ...EnumItem): ()Binds a named action at an explicit priority. The callback receives the action name, input state, and InputObject. Return Enum.ContextActionResult.Sink to consume the input or Pass to continue dispatch.
CreateActionContext
InputService:CreateActionContext(name: string, options: ActionContextOptions?): ActionContextCreates a named ActionContext with its own action bindings, priority, and modal behavior.
GetActionButton
InputService:GetActionButton(actionName: string): ImageButton?Returns the touch button created for the named action, or nil if no button exists.
GetBoundActions
InputService:GetBoundActions(): { BoundActionInfo }Returns information about the registered action bindings.
GetConnectedGamepads
InputService:GetConnectedGamepads(): { EnumItem }Returns the gamepad identifiers currently connected.
GetDevices
InputService:GetDevices(): tableReturns the input devices currently available to the player.
GetExecutionGroup
InputService:GetExecutionGroup(): ExecutionGroup?Returns this instance if it is an ExecutionGroup. Otherwise returns the nearest ancestor ExecutionGroup, or nil when no group contains the instance.
GetGamepadAxis
Returns the current axis value for the gamepad and key code.
GetGamepadConnected
InputService:GetGamepadConnected(gamepad: EnumItem): booleanReturns whether the specified gamepad is connected.
GetGamepadName
InputService:GetGamepadName(gamepad: EnumItem): string?Returns the device name of a connected gamepad, or nil if it is unavailable.
GetPressed
InputService:GetPressed(): tableReturns the inputs that are currently held down.
IsDown
InputService:IsDown(input: EnumItem): booleanTests whether a particular input is currently held.
IsGamepadButtonDown
Returns whether the specified gamepad button is pressed.
SetActionDescription
InputService:SetActionDescription(actionName: string, description: string): ()Sets the description of a named action's touch button.
SetActionImage
InputService:SetActionImage(actionName: string, image: string): ()Sets the image of a named action's touch button.
SetActionPosition
InputService:SetActionPosition(actionName: string, position: UDim2): ()Sets the position of a named action's touch button.
SetActionTitle
InputService:SetActionTitle(actionName: string, title: string): ()Sets the title of a named action's touch button.
SetGamepadButtonMap
Remaps a gamepad button. Pass nil as the destination to remove its mapping.
SetHaptic
InputService:SetHaptic(gamepad: EnumItem, strong: number, weak: number?, duration: number?): ()Sets gamepad vibration strengths and an optional duration in seconds.
UnbindAction
InputService:UnbindAction(actionName: string): ()Removes one named action binding.
UnbindAllActions
InputService:UnbindAllActions(): ()Removes all action bindings owned by the service.
Events
Began
InputService.Began: RBXScriptSignalFires when an input starts, such as a key going down or a button being pressed.
Changed
InputService.Changed: RBXScriptSignalFires when an ongoing input changes, such as pointer movement or a thumbstick axis changing.
Ended
InputService.Ended: RBXScriptSignalFires when an input stops.
GamepadConnected
InputService.GamepadConnected: RBXScriptSignalFires when a gamepad connects.
GamepadDisconnected
InputService.GamepadDisconnected: RBXScriptSignalFires when a gamepad disconnects.
PreferredInputChanged
InputService.PreferredInputChanged: RBXScriptSignalFires when the preferred input-device category changes.
TouchEnded
InputService.TouchEnded: RBXScriptSignalFires when a touch contact ends.
TouchMoved
InputService.TouchMoved: RBXScriptSignalFires when a touch contact moves.
TouchStarted
InputService.TouchStarted: RBXScriptSignalFires when a touch contact begins.
TouchTap
InputService.TouchTap: RBXScriptSignalFires when a touch tap is recognized.
Inherited members
- Properties
- ClassName
- Methods
- AddComponent()AddTag()ClearAllChildren()ClearTags()Clone()Destroy()FindFirstAncestor()FindFirstAncestorOfClass()FindFirstAncestorWhichIsA()FindFirstChild()FindFirstChildOfClass()FindFirstChildWhichIsA()FindFirstDescendant()GetAttribute()GetAttributeChangedSignal()GetAttributes()GetChildren()GetComponent()GetComponentChangedSignal()GetComponents()GetDebugId()GetDescendants()GetFullName()GetPropertyChangedSignal()GetReferencing()GetTags()HasComponent()HasTag()IsA()IsAncestorOf()IsDescendantOf()RemoveComponent()RemoveTag()SetAttribute()WaitForChild()
- Events
- AncestryChangedAttributeChangedChildAddedChildRemovedDescendantAddedDescendantRemovingDestroying
Example
local InputService = game:GetService("InputService")
InputService.Began:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard
and input.KeyCode == Enum.KeyCode.E then
print("E")
end
end)