ContextActionService - This combination of input types fires when the escape menu opens

Reproduction Steps
Insert a LocalScript into StarterPlayerScripts with this code and open the escape menu:

game:GetService("ContextActionService"):BindActionAtPriority(
    "WhyDoesEscapeMenuFireThis?",
    function(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject)
        print(actionName, inputState, inputObject.UserInputState, inputObject.KeyCode, inputObject.UserInputType)
        return Enum.ContextActionResult.Sink
    end,
    false,
    2000,
    Enum.KeyCode.F, Enum.KeyCode.ButtonY
)

Expected Behavior
I expect absolutely nothing to happen.

Actual Behavior
The following text is printed to the output three times:
WhyDoesEscapeMenuFireThis? Enum.UserInputState.Cancel Enum.UserInputState.Cancel Enum.KeyCode.Unknown Enum.UserInputType.None

Issue Area: Engine
Issue Type: Other
Impact: Moderate
Frequency: Constantly

3 Likes

This is expected behavior, Enum.UserInputState.Cancel is passed to an action handler when that action is bound over. This is because you might want to reset some state when the action gets bound over.

For example, if Enum.KeyCode.F toggles the fly state and the keycode is bound over by the escape menu opening you might want to automatically check if the user is in freefall and if so toggle back on the flying state. This way the user won’t frantically be pressing F with the escape menu open trying to save themselves from falling to their doom but be unable to actually use the action. A less made-up example is stopping the user from walking forward when W is bound over.

3 Likes

Ok, I guess…? If this behavior is to be expected, it should be properly documented somewhere, as I couldn’t find documentation on what buttons the Roblox CoreGui binds to and when.

That aside, I’m left with two questions:

  1. Why is my action handler being called three times for a single KeyCode?
  2. Why is the escape menu binding to the Y button for seemingly no reason? This means keyboard players will be unintentionally performing in-game actions each time they open the escape menu, even when there’s no gamepad enabled.

I definitely think the CoreGui should be documented better if there’s a chance that it will bind over my own actions, as this caught me entirely by surprise.

1 Like
  1. I would expect it to be called twice here, once for Enum.KeyCode.F and once for Enum.KeyCode.ButtonY. However maybe one of these is being bound over more than once.
  2. The escape menu binds over everything so that actions in the game no longer work when the in-game menu is open. For example it would be weird if you could still walk around while the in game menu was open.
2 Likes

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