学ぶ
エンジンクラス
ContextActionService
作成できません
サービス

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


概要
方法
BindAction(actionName: string,functionToBind: function,createTouchButton: boolean,inputTypes: Tuple):()
BindActionAtPriority(actionName: string,functionToBind: function,createTouchButton: boolean,priorityLevel: number,inputTypes: Tuple):()
BindActionToInputTypes(actionName: string,functionToBind: function,createTouchButton: boolean,inputTypes: Tuple):()
非推奨
BindActivate(userInputTypeForActivation: Enum.UserInputType,keyCodesForActivation: Tuple):()
SetDescription(actionName: string,description: string):()
SetImage(actionName: string,image: string):()
SetPosition(actionName: string,position: UDim2):()
SetTitle(actionName: string,title: string):()
UnbindAction(actionName: string):()
UnbindActivate(userInputTypeForActivation: Enum.UserInputType,keyCodeForActivation: Enum.KeyCode):()
継承されたメンバー
コードサンプル
ContextActionServiceツールのリロード
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "リロード"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("リロード中!")
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction(ACTION_RELOAD)
end)

APIリファレンス
方法
BindAction
機能: Input
ContextActionService:BindAction(
actionName:string, functionToBind:function, createTouchButton:boolean, inputTypes:Tuple
):()
パラメータ
actionName:string
functionToBind:function
createTouchButton:boolean
inputTypes:Tuple
戻り値
()
コードサンプル
ContextActionServiceツールのリロード
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "リロード"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("リロード中!")
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction(ACTION_RELOAD)
end)
一般的なアクションハンドラー
local ContextActionService = game:GetService("ContextActionService")
local function handleAction(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print("Handling action: " .. actionName)
print(inputObj.UserInputType)
end
-- この関数は何も返さないため、このハンドラーは
-- 入力を"sink"し、他のアクションハンドラーは
-- この後に呼び出されません。
end
ContextActionService:BindAction("BoundAction", handleAction, false, Enum.KeyCode.F)
スタックされたアクションハンドラー
local ContextActionService = game:GetService("ContextActionService")
-- FirstActionのためのアクションハンドラーを定義します
local function actionHandlerOne(actionName, inputState, _inputObj)
if inputState == Enum.UserInputState.Begin then
print("アクションハンドラー1: " .. actionName)
end
-- このアクションハンドラーはnilを返し、
-- アクションが適切に処理されていると仮定されます。
end
-- スタックの一番下にあるFirstActionをバインドします
ContextActionService:BindAction("FirstAction", actionHandlerOne, false, Enum.KeyCode.Z, Enum.KeyCode.X, Enum.KeyCode.C)
-- SecondActionのためのアクションハンドラーを定義します
local function actionHandlerTwo(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print("アクションハンドラー2: " .. actionName)
end
if inputObj.KeyCode == Enum.KeyCode.X then
return Enum.ContextActionResult.Pass
else
-- nilを返すことは暗黙的に入力を沈めます
return Enum.ContextActionResult.Sink
end
end
-- 最初のアクションの上にSecondActionをバインドします(最近バインドしたため、スタックの一番上にあります)
-- 注意: SecondActionは同じキーを使用しています
ContextActionService:BindAction("SecondAction", actionHandlerTwo, false, Enum.KeyCode.Z, Enum.KeyCode.X)

BindActionAtPriority
機能: Input
ContextActionService:BindActionAtPriority(
actionName:string, functionToBind:function, createTouchButton:boolean, priorityLevel:number, inputTypes:Tuple
):()
パラメータ
actionName:string
functionToBind:function
createTouchButton:boolean
priorityLevel:number
inputTypes:Tuple
戻り値
()
コードサンプル
ContextActionService の BindAction 優先度
local ContextActionService = game:GetService("ContextActionService")
local INPUT_KEY1 = Enum.KeyCode.Q
local INPUT_KEY2 = Enum.KeyCode.E
local function handleThrow(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject)
if inputState ~= Enum.UserInputState.Begin then
return Enum.ContextActionResult.Pass
end
print(`Action [{actionName}] occurred. KeyCode [{inputObject.KeyCode}] pressed.`)
return Enum.ContextActionResult.Sink
end
local function handlePunch(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject)
if inputState ~= Enum.UserInputState.Begin then
return Enum.ContextActionResult.Pass
end
print(`Action [{actionName}] occurred. KeyCode [{inputObject.KeyCode}] pressed.`)
return Enum.ContextActionResult.Sink
end
-- 優先度を指定せずに、最も最近バインドされたアクションが最初に呼ばれます。
-- したがって、INPUT_KEY1 を押すと "Punch" が印刷され、その後入力がシンクされます。
ContextActionService:BindAction("DefaultThrow", handleThrow, false, INPUT_KEY1)
ContextActionService:BindAction("DefaultPunch", handlePunch, false, INPUT_KEY1)
-- ここでは、上と同じ順序で両方の関数をバインドしますが、優先度が明示的に入れ替えられています。
-- つまり、"Throw" に優先度 2 を付与して最初に呼ばれるようにします。
-- これは、"Punch" がより最近バインドされているにもかかわらずです。
-- INPUT_KEY2 を押すと "Throw" が印刷され、その後入力がシンクされます。
ContextActionService:BindActionAtPriority("PriorityThrow", handleThrow, false, 2, INPUT_KEY2)
ContextActionService:BindActionAtPriority("PriorityPunch", handlePunch, false, 1, INPUT_KEY2)

BindActionToInputTypes
非推奨

BindActivate
機能: Input
ContextActionService:BindActivate(
userInputTypeForActivation:Enum.UserInputType, keyCodesForActivation:Tuple
):()
パラメータ
userInputTypeForActivation:Enum.UserInputType
keyCodesForActivation:Tuple
戻り値
()

GetAllBoundActionInfo
機能: Input
ContextActionService:GetAllBoundActionInfo():Dictionary
戻り値

GetBoundActionInfo
機能: Input
ContextActionService:GetBoundActionInfo(actionName:string):Dictionary
パラメータ
actionName:string
戻り値

GetButton
イールド
機能: Input
ContextActionService:GetButton(actionName:string):Instance
パラメータ
actionName:string
戻り値

GetCurrentLocalToolIcon
機能: Input
ContextActionService:GetCurrentLocalToolIcon():string
戻り値

SetDescription
機能: Input
ContextActionService:SetDescription(
actionName:string, description:string
):()
パラメータ
actionName:string
description:string
戻り値
()
コードサンプル
ContextActionService タッチボタン
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?のあるスピーチバブルの画像
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("インスペクト中")
end
end
-- タッチデバイスの場合、3番目のパラメータを介して画面上にボタンが自動的に作成されます
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- これらの関数を使用してボタンをカスタマイズできます:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "見る")
ContextActionService:SetDescription(ACTION_INSPECT, "何かをインスペクトします。")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButtonを使用してボタンを直接操作できます
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 忘れないで: 非タッチデバイスは何も返しません!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButtonを緑色に染める
end

SetImage
機能: Input
ContextActionService:SetImage(
actionName:string, image:string
):()
パラメータ
actionName:string
image:string
戻り値
()
コードサンプル
ContextActionService タッチボタン
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?のあるスピーチバブルの画像
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("インスペクト中")
end
end
-- タッチデバイスの場合、3番目のパラメータを介して画面上にボタンが自動的に作成されます
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- これらの関数を使用してボタンをカスタマイズできます:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "見る")
ContextActionService:SetDescription(ACTION_INSPECT, "何かをインスペクトします。")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButtonを使用してボタンを直接操作できます
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 忘れないで: 非タッチデバイスは何も返しません!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButtonを緑色に染める
end

SetPosition
機能: Input
ContextActionService:SetPosition(
actionName:string, position:UDim2
):()
パラメータ
actionName:string
position:UDim2
戻り値
()
コードサンプル
ContextActionService タッチボタン
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?のあるスピーチバブルの画像
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("インスペクト中")
end
end
-- タッチデバイスの場合、3番目のパラメータを介して画面上にボタンが自動的に作成されます
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- これらの関数を使用してボタンをカスタマイズできます:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "見る")
ContextActionService:SetDescription(ACTION_INSPECT, "何かをインスペクトします。")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButtonを使用してボタンを直接操作できます
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 忘れないで: 非タッチデバイスは何も返しません!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButtonを緑色に染める
end

SetTitle
機能: Input
ContextActionService:SetTitle(
actionName:string, title:string
):()
パラメータ
actionName:string
title:string
戻り値
()
コードサンプル
ContextActionService タッチボタン
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?のあるスピーチバブルの画像
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("インスペクト中")
end
end
-- タッチデバイスの場合、3番目のパラメータを介して画面上にボタンが自動的に作成されます
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- これらの関数を使用してボタンをカスタマイズできます:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "見る")
ContextActionService:SetDescription(ACTION_INSPECT, "何かをインスペクトします。")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButtonを使用してボタンを直接操作できます
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 忘れないで: 非タッチデバイスは何も返しません!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButtonを緑色に染める
end

UnbindAction
機能: Input
ContextActionService:UnbindAction(actionName:string):()
パラメータ
actionName:string
戻り値
()
コードサンプル
ContextActionServiceツールのリロード
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "リロード"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("リロード中!")
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction(ACTION_RELOAD)
end)

UnbindActivate
機能: Input
ContextActionService:UnbindActivate(
userInputTypeForActivation:Enum.UserInputType, keyCodeForActivation:Enum.KeyCode
):()
パラメータ
userInputTypeForActivation:Enum.UserInputType
keyCodeForActivation:Enum.KeyCode
既定値: "Unknown"
戻り値
()

UnbindAllActions
機能: Input
ContextActionService:UnbindAllActions():()
戻り値
()

イベント
LocalToolEquipped
機能: Input
ContextActionService.LocalToolEquipped(toolEquipped:Instance):RBXScriptSignal
パラメータ
toolEquipped:Instance

LocalToolUnequipped
機能: Input
ContextActionService.LocalToolUnequipped(toolUnequipped:Instance):RBXScriptSignal
パラメータ
toolUnequipped:Instance

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。