Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you use multiple Keyboard inputs?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
)

0
I tried it, but therre was an Error at line 14 and 15. On BindAction and KeyPress turbomegapower12345 48 — 5y
0
There isn't even a line 14 or 15 on that script? You must have kept something else Warfaresh0t 414 — 5y
Ad

Answer this question