# ContextActionService

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Tags: Not creatable, Service
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/ContextActionService/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/ContextActionService

A service used to bind user input to contextual actions.

## Methods

### BindAction

```luau
ContextActionService:BindAction(actionName: string, functionToBind: (...any) -> ...any, createTouchButton: boolean, ...: any)
```

- Tags: Capabilities: Input

Bind user input to an action given an action handling function.

Parameters:

- `actionName`: A string representing the action being performed (e.g. "HonkHorn" or "OpenDoor").
- `functionToBind`: The action-handling function, called with the following parameters when the bound inputs are triggered: string (actionName), `UserInputState` and an InputObject.
- `createTouchButton`: Whether a GUI button should be created for the action on touch input devices.
- `inputTypes`: Any number of `KeyCode` or `UserInputType` representing the inputs to bind to the action.

### BindActionAtPriority

```luau
ContextActionService:BindActionAtPriority(actionName: string, functionToBind: (...any) -> ...any, createTouchButton: boolean, priorityLevel: number, ...: any)
```

- Tags: Capabilities: Input

Behaves like [`BindAction`](https://rapi.sleaze.dev/classes/ContextActionService.md) but also allows a priority to be assigned to the bound action for overlapping input types (higher before lower).

Parameters:

- `actionName`: A string representing the action being performed (e.g. "HonkHorn" or "OpenDoor").
- `functionToBind`: The action-handling function, called with the following parameters when the bound inputs are triggered: string (actionName), `UserInputState` and an InputObject.
- `createTouchButton`: Whether a GUI button should be created for the action on touch input devices.
- `priorityLevel`: The priority level at which the action should be bound (higher considered before lower).
- `inputTypes`: Any number of Enum.KeyCode or Enum.UserInputType representing the inputs to bind to the action.

### BindActivate

```luau
ContextActionService:BindActivate(userInputTypeForActivation: Enum.UserInputType, ...: any)
```

- Tags: Capabilities: Input

Bind a `KeyCode` with a specific `UserInputType` to trigger `Tool.Activation` and [`ClickDetector`](https://rapi.sleaze.dev/classes/ClickDetector.md) events.

Parameters:

- `userInputTypeForActivation`: Must be Keyboard or Gamepad1 through Gamepad8.
- `keyCodesForActivation`: Any number of `KeyCode` values that trigger [`Tool`](https://rapi.sleaze.dev/classes/Tool.md) activation for the specified `UserInputType`.

### BindCoreAction

```luau
ContextActionService:BindCoreAction(actionName: string, functionToBind: (...any) -> ...any, createTouchButton: boolean, ...: any)
```

- Tags: Roblox script security, Capabilities: Input

### BindCoreActionAtPriority

```luau
ContextActionService:BindCoreActionAtPriority(actionName: string, functionToBind: (...any) -> ...any, createTouchButton: boolean, priorityLevel: number, ...: any)
```

- Tags: Roblox script security, Capabilities: Input

### BindCoreActivate

```luau
ContextActionService:BindCoreActivate(userInputTypeForActivation: Enum.UserInputType, ...: any)
```

- Tags: Roblox script security, Capabilities: Input

### CallFunction

```luau
ContextActionService:CallFunction(actionName: string, state: Enum.UserInputState, inputObject: Instance): ...any
```

- Tags: Roblox script security, Capabilities: Input

### FireActionButtonFoundSignal

```luau
ContextActionService:FireActionButtonFoundSignal(actionName: string, actionButton: Instance)
```

- Tags: Roblox script security, Capabilities: Input

### GetAllBoundActionInfo

```luau
ContextActionService:GetAllBoundActionInfo(): { [string]: any }
```

- Tags: Capabilities: Input

Get a table of information about all bound actions (key is the name passed to [`BindAction`](https://rapi.sleaze.dev/classes/ContextActionService.md), value is a table from [`GetBoundActionInfo`](https://rapi.sleaze.dev/classes/ContextActionService.md) when called with the key).

Returns: A dictionary mapping each bound action name to its info table.

### GetAllBoundCoreActionInfo

```luau
ContextActionService:GetAllBoundCoreActionInfo(): { [string]: any }
```

- Tags: Roblox script security, Capabilities: Input

### GetBoundActionInfo

```luau
ContextActionService:GetBoundActionInfo(actionName: string): { [string]: any }
```

- Tags: Capabilities: Input

Get a table of information about a bound action given its name originally passed to [`BindAction`](https://rapi.sleaze.dev/classes/ContextActionService.md).

Parameters:

- `actionName`: The name of the action originally passed to BindAction.

Returns: A dictionary with keys describing the bound action, including stackOrder, priorityLevel, createTouchButton, inputTypes, description, title, and image.

### GetBoundCoreActionInfo

```luau
ContextActionService:GetBoundCoreActionInfo(actionName: string): { [string]: any }
```

- Tags: Roblox script security, Capabilities: Input

### GetButton

```luau
ContextActionService:GetButton(actionName: string): Instance
```

- Tags: Yields, Capabilities: Input

Retrieves a [`ImageButton`](https://rapi.sleaze.dev/classes/ImageButton.md) of a `bound` action that had a touch input button created.

Parameters:

- `actionName`: The name of the action originally passed to BindAction.

Returns: An ImageButton created by BindAction.

### GetCurrentLocalToolIcon

```luau
ContextActionService:GetCurrentLocalToolIcon(): string
```

- Tags: Capabilities: Input

Return the [`BackpackItem.TextureId`](https://rapi.sleaze.dev/classes/BackpackItem.md) of a [`Tool`](https://rapi.sleaze.dev/classes/Tool.md) currently `equipped` by the [`Player`](https://rapi.sleaze.dev/classes/Player.md).

Returns: A content string from the Tool's TextureId, or `nil` if one could not be found.

### GetInputContexts

```luau
ContextActionService:GetInputContexts(): { Instance }
```

- Tags: Roblox script security, Capabilities: Input

### GetInputSchemaKeyCodeTree

```luau
ContextActionService:GetInputSchemaKeyCodeTree(): { [string]: any }
```

- Tags: Roblox script security, Capabilities: Input

### SetDescription

```luau
ContextActionService:SetDescription(actionName: string, description: string)
```

- Tags: Capabilities: Input

Given the name of a bound action with a touch button, sets the description of the action.

Parameters:

- `actionName`: The name of the action originally passed to BindAction.
- `description`: A text description of the action, such as "Honk the car's horn" or "Open the inventory".

### SetImage

```luau
ContextActionService:SetImage(actionName: string, image: string)
```

- Tags: Capabilities: Input

If `actionName` key contains a bound action, then `image` is set as the image of the touch button.

Parameters:

- `actionName`: The name of the action originally passed to BindAction.
- `image`: The value to which the Image property should be set.

### SetPosition

```luau
ContextActionService:SetPosition(actionName: string, position: UDim2)
```

- Tags: Capabilities: Input

Given the name of a bound action with a touch button, sets the position of the button within the ContextButtonFrame.

Parameters:

- `actionName`: The name of the action originally passed to BindAction.
- `position`: The position within the ContextButtonFrame.

### SetTitle

```luau
ContextActionService:SetTitle(actionName: string, title: string)
```

- Tags: Capabilities: Input

Given the name of a bound action with a touch button, sets the text shown on the button.

Parameters:

- `actionName`: The name of the action originally passed to BindAction.
- `title`: The text to display on the button.

### UnbindAction

```luau
ContextActionService:UnbindAction(actionName: string)
```

- Tags: Capabilities: Input

Unbind an action from input given its name.

Parameters:

- `actionName`: The name of the action to unbind, as originally passed to BindAction.

### UnbindActivate

```luau
ContextActionService:UnbindActivate(userInputTypeForActivation: Enum.UserInputType, keyCodeForActivation: Enum.KeyCode? = Enum.KeyCode.None)
```

- Tags: Capabilities: Input

Unbind a `KeyCode` with a specific `UserInputType` from triggering `Tool.Activation` when bound with [`ContextActionService:BindActivate()`](https://rapi.sleaze.dev/classes/ContextActionService.md).

Parameters:

- `userInputTypeForActivation`: The same UserInputType originally sent to BindActivate.
- `keyCodeForActivation`: The same KeyCode originally sent to BindActivate.

### UnbindAllActions

```luau
ContextActionService:UnbindAllActions()
```

- Tags: Capabilities: Input

Removes all functions bound. No actionNames will remain. All touch buttons will be removed.

### UnbindCoreAction

```luau
ContextActionService:UnbindCoreAction(actionName: string)
```

- Tags: Roblox script security, Capabilities: Input

### UnbindCoreActivate

```luau
ContextActionService:UnbindCoreActivate(userInputTypeForActivation: Enum.UserInputType, keyCodeForActivation: Enum.KeyCode? = Enum.KeyCode.None)
```

- Tags: Roblox script security, Capabilities: Input

### BindActionToInputTypes

```luau
ContextActionService:BindActionToInputTypes(actionName: string, functionToBind: (...any) -> ...any, createTouchButton: boolean, ...: any)
```

- Tags: Deprecated, Capabilities: Input
- Use instead: [`ContextActionService.BindAction`](https://rapi.sleaze.dev/classes/ContextActionService.md)

**Deprecated:** This item has been superseded by [`ContextActionService:BindAction()`](https://rapi.sleaze.dev/classes/ContextActionService.md) which should be used in all new work.

Binds *functionToBind* to input events such as key presses, mouse movement, or controller input.

## Events

### BoundActionAdded

```luau
ContextActionService.BoundActionAdded: RBXScriptSignal<(actionAdded: string, createTouchButton: boolean, functionInfoTable: { [string]: any }, isCore: boolean)>
```

- Tags: Roblox script security, Capabilities: Input

### BoundActionChanged

```luau
ContextActionService.BoundActionChanged: RBXScriptSignal<(actionChanged: string, changeName: string, changeTable: { [string]: any })>
```

- Tags: Roblox script security, Capabilities: Input

### BoundActionRemoved

```luau
ContextActionService.BoundActionRemoved: RBXScriptSignal<(actionRemoved: string, functionInfoTable: { [string]: any }, isCore: boolean)>
```

- Tags: Roblox script security, Capabilities: Input

### GetActionButtonEvent

```luau
ContextActionService.GetActionButtonEvent: RBXScriptSignal<(actionName: string)>
```

- Tags: Roblox script security, Capabilities: Input

### InputContextsChanged

```luau
ContextActionService.InputContextsChanged: RBXScriptSignal<()>
```

- Tags: Roblox script security, Capabilities: Input

### LocalToolEquipped

```luau
ContextActionService.LocalToolEquipped: RBXScriptSignal<(toolEquipped: Instance)>
```

- Tags: Capabilities: Input

Fires when the current player equips a [`Tool`](https://rapi.sleaze.dev/classes/Tool.md).

### LocalToolUnequipped

```luau
ContextActionService.LocalToolUnequipped: RBXScriptSignal<(toolUnequipped: Instance)>
```

- Tags: Capabilities: Input

Fires when the current player unequips a [`Tool`](https://rapi.sleaze.dev/classes/Tool.md).

### OpenInputActionManagerSignal

```luau
ContextActionService.OpenInputActionManagerSignal: RBXScriptSignal<(selectedInputObjects: { Instance })>
```

- Tags: Roblox script security, Capabilities: Input

## Inherited members

- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
