Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can you use multiple Keyboard inputs?

Hi, This question is something I have been wondering for a long time, and I need someone to answer this question.

I put this code in a local script, that was in starter player scripts.

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("R was pressed")
	end
end
 
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)

then I put this code in another local script that also went in Starter Player Scripts.

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("E was pressed")
	end
end
 
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.E)

the Keyboard inputs did not work? so how do I use multiple keyboard inputs?

1 answer

###This is possible. The fourth argument (keys to bind) is a tuple, which can be multiple arguments.

local function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        print(inputObject.KeyCode.Name, "was pressed")
    end
end

game:GetService("ContextActionService")BindAction(
    "keyPress", 
    onKeyPress, 
    false, 
    Enum.KeyCode.R,  -- assign multiple keys like this
    Enum.KeyCode.E
)

2 comments

0

I tried it, but therre was an Error at line 14 and 15. On BindAction and KeyPress

0

There isn't even a line 14 or 15 on that script? You must have kept something else

This discussion is preserved as it was. New answers, comments, and votes are closed.