Open Asterune
InputService

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

Members46
Properties14
Methods22
Events10
  • Began: RBXScriptSignalparallel read

    Fires when an input starts, such as a key going down or a button being pressed.

  • Changed: RBXScriptSignalparallel readoverrides Instance

    Fires when an ongoing input changes, such as pointer movement or a thumbstick axis changing.

  • Ended: RBXScriptSignalparallel read

    Fires when an input stops.

  • GamepadConnected: RBXScriptSignalparallel readread only

    Fires when a gamepad connects.

  • GamepadDisconnected: RBXScriptSignalparallel readread only

    Fires when a gamepad disconnects.

  • PreferredInputChanged: RBXScriptSignalparallel readread only

    Fires when the preferred input-device category changes.

  • TouchEnded: RBXScriptSignalparallel readread only

    Fires when a touch contact ends.

  • TouchMoved: RBXScriptSignalparallel readread only

    Fires when a touch contact moves.

  • TouchStarted: RBXScriptSignalparallel readread only

    Fires when a touch contact begins.

  • TouchTap: RBXScriptSignalparallel readread only

    Fires when a touch tap is recognized.

Properties

Archivable

InputService.Archivable: boolean = true

Whether the service instance is included when its containing hierarchy is cloned or saved. The default is true.

GamepadDeadZone

InputService.GamepadDeadZone: number

The analog input magnitude below which gamepad movement is ignored.

KeyboardEnabled

InputService.KeyboardEnabled: boolean

Whether keyboard input is available.

LastDevice

InputService.LastDevice: EnumItem

The device that most recently produced input, useful for choosing control hints.

MouseBehavior

InputService.MouseBehavior: EnumItem

The pointer locking mode.

MouseEnabled

InputService.MouseEnabled: boolean

Whether mouse input is available.

MouseIconEnabled

InputService.MouseIconEnabled: boolean

Whether the pointer icon is displayed.

Name

InputService.Name: string = "InputService"

The instance name. The default is "InputService".

OnScreenKeyboardPosition

InputService.OnScreenKeyboardPosition: Vector2

The on-screen keyboard's position in pixels.

OnScreenKeyboardSize

InputService.OnScreenKeyboardSize: Vector2

The on-screen keyboard's size in pixels.

OnScreenKeyboardVisible

InputService.OnScreenKeyboardVisible: boolean

Whether the on-screen keyboard is visible.

Parent

InputService.Parent: Instance? = nil

The service's parent instance. The default is nil.

PreferredInput

InputService.PreferredInput: EnumItem

The input-device category currently preferred by the player.

TouchEnabled

InputService.TouchEnabled: boolean

Whether 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?): ActionContext

Creates 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(): table

Returns 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

InputService:GetGamepadAxis(gamepad: EnumItem, keyCode: EnumItem): Vector3

Returns the current axis value for the gamepad and key code.

GetGamepadConnected

InputService:GetGamepadConnected(gamepad: EnumItem): boolean

Returns 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(): table

Returns the inputs that are currently held down.

IsDown

InputService:IsDown(input: EnumItem): boolean

Tests whether a particular input is currently held.

IsGamepadButtonDown

InputService:IsGamepadButtonDown(gamepad: EnumItem, keyCode: EnumItem): boolean

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

InputService:SetGamepadButtonMap(from: EnumItem, to: EnumItem?): ()

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: RBXScriptSignal

Fires when an input starts, such as a key going down or a button being pressed.

Changed

InputService.Changed: RBXScriptSignal

Fires when an ongoing input changes, such as pointer movement or a thumbstick axis changing.

Ended

InputService.Ended: RBXScriptSignal

Fires when an input stops.

GamepadConnected

InputService.GamepadConnected: RBXScriptSignal

Fires when a gamepad connects.

GamepadDisconnected

InputService.GamepadDisconnected: RBXScriptSignal

Fires when a gamepad disconnects.

PreferredInputChanged

InputService.PreferredInputChanged: RBXScriptSignal

Fires when the preferred input-device category changes.

TouchEnded

InputService.TouchEnded: RBXScriptSignal

Fires when a touch contact ends.

TouchMoved

InputService.TouchMoved: RBXScriptSignal

Fires when a touch contact moves.

TouchStarted

InputService.TouchStarted: RBXScriptSignal

Fires when a touch contact begins.

TouchTap

InputService.TouchTap: RBXScriptSignal

Fires when a touch tap is recognized.

Inherited members

Inherited43

Example

Luau
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)

InputObject · Enum.KeyCode · Enum.UserInputType