Informacje o wersji
Edukacja
Klasa silnika
ContextActionService
Brak możliwości tworzenia
Usługa

*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.


Podsumowanie
Metody
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):()
Przestarzałe
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):()
Członkowie odziedziczeni
Przykłady kodu
Narzędzie do przeładowania ContextActionService
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Przeładuj"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Przeładowanie!")
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)

Materiały referencyjne dotyczące interfejsów API
Metody
BindAction
Możliwości: Input
ContextActionService:BindAction(
actionName:string, functionToBind:function, createTouchButton:boolean, inputTypes:Tuple
):()
Parametry
actionName:string
functionToBind:function
createTouchButton:boolean
inputTypes:Tuple
Zwroty
()
Przykłady kodu
Narzędzie do przeładowania ContextActionService
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Przeładuj"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Przeładowanie!")
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)
Ogólny obsługiwacz akcji
local ContextActionService = game:GetService("ContextActionService")
local function handleAction(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print("Obsługa akcji: " .. actionName)
print(inputObj.UserInputType)
end
-- Ponieważ ta funkcja nie zwraca niczego, ten obsługiwacz
-- "wchłonie" dane wejściowe i żadne inne obsługiwacze akcji nie
-- będą wywołane po tym.
end
ContextActionService:BindAction("BoundAction", handleAction, false, Enum.KeyCode.F)
Poukładane Obsługi Akcji
local ContextActionService = game:GetService("ContextActionService")
-- Zdefiniuj funkcję obsługi akcji dla FirstAction
local function actionHandlerOne(actionName, inputState, _inputObj)
if inputState == Enum.UserInputState.Begin then
print("Obsługa Akcji Pierwszej: " .. actionName)
end
-- Ta funkcja obsługi akcji zwraca nil, więc zakłada się, że
-- poprawnie obsługuje akcję.
end
-- Łączenie akcji FirstAction (jest na dole stosu)
ContextActionService:BindAction("FirstAction", actionHandlerOne, false, Enum.KeyCode.Z, Enum.KeyCode.X, Enum.KeyCode.C)
-- Zdefiniuj funkcję obsługi akcji dla SecondAction
local function actionHandlerTwo(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print("Obsługa Akcji Drugiej: " .. actionName)
end
if inputObj.KeyCode == Enum.KeyCode.X then
return Enum.ContextActionResult.Pass
else
-- Zwracając nil, implikacyjnie zatapia wejścia
return Enum.ContextActionResult.Sink
end
end
-- Łączenie SecondAction nad pierwszą akcją (ponieważ została połączona później, jest na górze stosu)
-- Zauważ, że SecondAction używa tych samych klawiszy co
ContextActionService:BindAction("SecondAction", actionHandlerTwo, false, Enum.KeyCode.Z, Enum.KeyCode.X)

BindActionAtPriority
Możliwości: Input
ContextActionService:BindActionAtPriority(
actionName:string, functionToBind:function, createTouchButton:boolean, priorityLevel:number, inputTypes:Tuple
):()
Parametry
actionName:string
functionToBind:function
createTouchButton:boolean
priorityLevel:number
inputTypes:Tuple
Zwroty
()
Przykłady kodu
Priorytety BindActionService 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(`Akcja [{actionName}] miała miejsce. Klawisz [{inputObject.KeyCode}] został wciśnięty.`)
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(`Akcja [{actionName}] miała miejsce. Klawisz [{inputObject.KeyCode}] został wciśnięty.`)
return Enum.ContextActionResult.Sink
end
-- Nie określając priorytetu, najnowsza przypisana akcja jest wywoływana jako pierwsza,
-- więc wciśnięcie INPUT_KEY1 wypisuje "Cios" i następnie przeszło do podania.
ContextActionService:BindAction("DefaultThrow", handleThrow, false, INPUT_KEY1)
ContextActionService:BindAction("DefaultPunch", handlePunch, false, INPUT_KEY1)
-- Tutaj przypisujemy obie funkcje w tej samej kolejności co powyżej, ale z wyraźnie zamienionymi priorytetami.
-- To znaczy, dajemy "Rzucenie" wyższy priorytet 2, aby było wywołane jako pierwsze,
-- mimo że "Cios" nadal jest przypisany niedawno.
-- Wciśnięcie INPUT_KEY2 wypisuje "Rzucenie" i następnie przeszło do podania.
ContextActionService:BindActionAtPriority("PriorityThrow", handleThrow, false, 2, INPUT_KEY2)
ContextActionService:BindActionAtPriority("PriorityPunch", handlePunch, false, 1, INPUT_KEY2)

BindActionToInputTypes
Przestarzałe

BindActivate
Możliwości: Input
ContextActionService:BindActivate(
userInputTypeForActivation:Enum.UserInputType, keyCodesForActivation:Tuple
):()
Parametry
userInputTypeForActivation:Enum.UserInputType
keyCodesForActivation:Tuple
Zwroty
()

GetAllBoundActionInfo
Możliwości: Input
ContextActionService:GetAllBoundActionInfo():Dictionary

GetBoundActionInfo
Możliwości: Input
ContextActionService:GetBoundActionInfo(actionName:string):Dictionary
Parametry
actionName:string

GetButton
Wynik
Możliwości: Input
ContextActionService:GetButton(actionName:string):Instance
Parametry
actionName:string
Zwroty

GetCurrentLocalToolIcon
Możliwości: Input
ContextActionService:GetCurrentLocalToolIcon():string
Zwroty

SetDescription
Możliwości: Input
ContextActionService:SetDescription(
actionName:string, description:string
):()
Parametry
actionName:string
description:string
Zwroty
()
Przykłady kodu
UsługaAkcjiKontekstu Przycisk Dotykowy
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspekcja"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Obraz chmurki z pytajnikiem
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspektowanie")
end
end
-- Dla urządzeń dotykowych, przycisk jest tworzony na ekranie automatycznie za pomocą 3. parametru
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- Możemy użyć tych funkcji, aby dostosować przycisk:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Patrz")
ContextActionService:SetDescription(ACTION_INSPECT, "Zbadaj coś.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- Możemy manipulować przyciskiem bezpośrednio używając ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Pamiętaj: urządzenia nie dotykowe nie zwrócą niczego!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Zabarw obraz ImageButton na zielono
end

SetImage
Możliwości: Input
ContextActionService:SetImage(
actionName:string, image:string
):()
Parametry
actionName:string
image:string
Zwroty
()
Przykłady kodu
UsługaAkcjiKontekstu Przycisk Dotykowy
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspekcja"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Obraz chmurki z pytajnikiem
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspektowanie")
end
end
-- Dla urządzeń dotykowych, przycisk jest tworzony na ekranie automatycznie za pomocą 3. parametru
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- Możemy użyć tych funkcji, aby dostosować przycisk:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Patrz")
ContextActionService:SetDescription(ACTION_INSPECT, "Zbadaj coś.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- Możemy manipulować przyciskiem bezpośrednio używając ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Pamiętaj: urządzenia nie dotykowe nie zwrócą niczego!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Zabarw obraz ImageButton na zielono
end

SetPosition
Możliwości: Input
ContextActionService:SetPosition(
actionName:string, position:UDim2
):()
Parametry
actionName:string
position:UDim2
Zwroty
()
Przykłady kodu
UsługaAkcjiKontekstu Przycisk Dotykowy
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspekcja"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Obraz chmurki z pytajnikiem
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspektowanie")
end
end
-- Dla urządzeń dotykowych, przycisk jest tworzony na ekranie automatycznie za pomocą 3. parametru
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- Możemy użyć tych funkcji, aby dostosować przycisk:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Patrz")
ContextActionService:SetDescription(ACTION_INSPECT, "Zbadaj coś.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- Możemy manipulować przyciskiem bezpośrednio używając ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Pamiętaj: urządzenia nie dotykowe nie zwrócą niczego!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Zabarw obraz ImageButton na zielono
end

SetTitle
Możliwości: Input
ContextActionService:SetTitle(
actionName:string, title:string
):()
Parametry
actionName:string
title:string
Zwroty
()
Przykłady kodu
UsługaAkcjiKontekstu Przycisk Dotykowy
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspekcja"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Obraz chmurki z pytajnikiem
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspektowanie")
end
end
-- Dla urządzeń dotykowych, przycisk jest tworzony na ekranie automatycznie za pomocą 3. parametru
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- Możemy użyć tych funkcji, aby dostosować przycisk:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Patrz")
ContextActionService:SetDescription(ACTION_INSPECT, "Zbadaj coś.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- Możemy manipulować przyciskiem bezpośrednio używając ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Pamiętaj: urządzenia nie dotykowe nie zwrócą niczego!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Zabarw obraz ImageButton na zielono
end

UnbindAction
Możliwości: Input
ContextActionService:UnbindAction(actionName:string):()
Parametry
actionName:string
Zwroty
()
Przykłady kodu
Narzędzie do przeładowania ContextActionService
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Przeładuj"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Przeładowanie!")
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
Możliwości: Input
ContextActionService:UnbindActivate(
userInputTypeForActivation:Enum.UserInputType, keyCodeForActivation:Enum.KeyCode
):()
Parametry
userInputTypeForActivation:Enum.UserInputType
keyCodeForActivation:Enum.KeyCode
Wartość domyślna: "Unknown"
Zwroty
()

UnbindAllActions
Możliwości: Input
ContextActionService:UnbindAllActions():()
Zwroty
()

Zdarzenia
LocalToolEquipped
Możliwości: Input
ContextActionService.LocalToolEquipped(toolEquipped:Instance):RBXScriptSignal
Parametry
toolEquipped:Instance

LocalToolUnequipped
Możliwości: Input
ContextActionService.LocalToolUnequipped(toolUnequipped:Instance):RBXScriptSignal
Parametry
toolUnequipped:Instance

©2026 Roblox Corporation. Nazwa Roblox, logo Roblox oraz hasło „Powering Imagination” należą do naszych zarejestrowanych i niezarejestrowanych znaków towarowych na terenie Stanów Zjednoczonych oraz w innych krajach.