배우기
엔진 클래스
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("액션 핸들러 원: " .. 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("액션 핸들러 투: " .. actionName)
end
if inputObj.KeyCode == Enum.KeyCode.X then
return Enum.ContextActionResult.Pass
else
-- nil을 반환하면 암묵적으로 입력을 가라앉힙니다.
return Enum.ContextActionResult.Sink
end
end
-- 가장 최근에 바인딩된 FirstAction 위에 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 바인드 액션 우선순위
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
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
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
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
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
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
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
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
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'은 미국 및 기타 국가 내 당사의 등록 및 미등록 상표입니다.