BindActionAtPriority firing Enum.KeyCode.Unknown

The Unknown key code is able to fire actions bound to Space key code. Paste the following code example in a local script in a baseplate, play solo and press Space- it will print correctly. Then press escape to open Roblox menu- this will print Enum.KeyCode.Unknown.

game.ContextActionService:BindActionAtPriority("Wheelie", function(actionName, state, input)
	print(input.KeyCode)
	if input.KeyCode == Enum.KeyCode.Space then
		if state == Enum.UserInputState.Begin then
			return Enum.ContextActionResult.Sink
		elseif state == Enum.UserInputState.End then
			return Enum.ContextActionResult.Sink
		end

		return Enum.ContextActionResult.Pass
	end
end,false, 2001, Enum.KeyCode.Space)

So receiving Enum.KeyCode.Unknown itself isn’t really a problem here. The usage for this is documented in this section of the ContextActionService documentation.

Looking into this though, it seems that when “jumpAction” is being bound and unbound, causing this cancel action to be sent. Realistically, that shouldn’t be sent unless your action is actively being overridden, so I’ll go ahead and make a change that should fix this case.

1 Like

So, on further inspection, it looks like we bind a new “Core Action” which refers to a Roblox internal action to override the spacebar when entering the settings menu. This is specifically meant to override the spacebar, so that users cannot jump while in the menu.

In other words, this is actually working as intended, in your case it might be best just to early return in your function if you encounter an Enum.KeyCode.Unknown, Enum.UserInputState.Cancel, or Enum.UserInputType.None.

Thanks for taking a look into it! I implemented a fix on our end after posting this but is good knowledge for future people running into this.

1 Like

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