Keycode for ContextActionService

Hi i am trying to bind a function when the player’s Right Mouse button is held and let go.
Is there any Enum.Keycode for this? Because i can’t bind Player:GetMouse().

image

Anyways this is the script:

ContextActionService:BindAction("ZoomIn", function(p3, InputState, p5)
    if InputState == Enum.UserInputState.Begin then
        Zoom("In") -- function zoom in
    end
end, true, Enum.KeyCode.?) -- what keycode for right mouse button down???

Try Enum.UserInputType.MouseButton2

Thank you! I was looking for this keybind.
Do you also maybe know how i could detect it if the player holds it/let go of the keybind?

If you would like to do it that way, please consider using Mouse. So there are 2 methods that might be helpful; Button2Up, Button2Down (For right click.)

You have to set up a boolean outside the event, and keep tracking if the player is still holding the right click.

local rightHold = false

mouse.Button2Down:Connect(function()
    rightHold = true   -- Holding
end)

mouse.Button2Up:Connect(function()
    rightHold = false   -- Release
end)

Hi, i’ve already tried this but my game needs to have mobile support since a major part of my game plays on mobile. Is there really no possible way to detect if the player is holding Enum.UserInputType.MouseButton2?

Then try using UserInputService with these 2 methods instead; InputBegan and InputEnded and detect for Enum.UserInputType.MouseButton2

2 Likes

You can still use ContextActionService to detect if the right mouse button is held down! This can be done with the InputState parameter. You would just have to also check for when the inputstate has ended like so:

ContextActionService:BindAction("ZoomIn", function(p3, InputState, p5)
    if InputState == Enum.UserInputState.Begin then
        Zoom("In") -- function zoom in
    elseif InputState == Enum.UserInputState.End then
        --<< Input has ended >>--
    end
end, true, Enum.UserInputType.MouseButton2)

Both methods work but it just depends on what you prefer! Hope this helps!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.