ContextActionService with more than one input

What do I want achieve?

I want make a contextactionService with more than one input:

What have I tried so far?

I did but its not that good “S” and “Q” can be used for the same input to print(“hey”)

my Script:

local function handleAction(actionName, inputState, inputObject)
	if actionName == Properties.Action and inputState == Enum.UserInputState.Begin 
		and Properties.pressedQ == false then
		Properties.pressedQ = true
	end
	if actionName == Properties.Action and inputState == Enum.UserInputState.Begin  then
		print("hey")
	end
end

CAS:BindAction(Properties.Action, handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.S)

Can somoene please help? Please

I’m a little confused on what you mean by this

I just want an input with more than once in ContextActionService

and both should have different outputs

I’m still a little confused but I think I understand what you’re trying to say.

local function handleAction(actionName, inputState, inputObject)
    local pressedQ = (inputObject.KeyCode == Enum.KeyCode.Q)
    local pressedS = (inputObject.KeyCode == Enum.KeyCode.S)

    if actionName == Properties.Action and inputState == Enum.UserInputState.Begin then
        if pressedQ then -- check if they pressed the Q button
           print("pressed 'Q'") 
        else -- otherwise they pressed S
           print("pressed 'S'")
        end

        print('hey')
        return Enum.ContextActionResult.Pass -- passes the input
    else
        return Enum.ContextActionResult.Sink -- sinks the input
    end
end

CAS:BindAction(Properties.Action, handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.S)

Is this what you mean?

a second I will test it I clicked too fast solution

can you make it like I can add (if I want) more than one input. Looks like it is just limited on 2 inputs

This prints the name of all of the keycodes that are pressed. If you want boolean variables for different keys, you’d have to modify the script I previously sent (just follow what I did).

local function handleAction(actionName, inputState, inputObject)
    if actionName == Properties.Action and inputState == Enum.UserInputState.Begin then
        print(string.format("pressed '%s'", inputObject.KeyCode.Name)) -- prints the name of the keycode that was pressed

        print('hey')
        return Enum.ContextActionResult.Pass -- passes the input
    else
        return Enum.ContextActionResult.Sink -- sinks the input
    end
end

CAS:BindAction(Properties.Action, handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.S)

CAS:BindAction(Properties.Action, handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.S)


For more input detection, add more keycodes at the end of the function.

example

local pressedE = (inputObject.KeyCode == Enum.KeyCode.E)

if pressedE then
   print("pressed 'E'")
else
   print("pressed another key")
end
1 Like