XButton Keycode fired when ESC is pushed

Hey there,

I’m currently using ContextActionService to detect keyboard and controller inputs. I’m trying to detect Enum/KeyCode/XButton so that I can add controller support to my game, however, when I press ESC on the keyboard with no controller connected the XButton fires. Like with my last post I’m not sure if this is intentional but wanted to post in case it isn’t.

Using this code and pressing ESC in Play Solo will fire the bound function -

game:GetService("ContextActionService"):BindAction("Xbox_X", (function() print("X") end), false, Enum.KeyCode.ButtonX);

**Edit. This happens with ButtonY and ButtonB too.

Many thanks,
Richard.

1 Like

Well, kinda. It’s firing with a “Cancel” UserInputState, and for some reason doesn’t pass the KeyCode either:

local function Button(name, inputState, inputObj)
	print(inputState, inputObj.KeyCode)
end

game:GetService("ContextActionService"):BindAction(
	"Test",
	Button,
	false,
	Enum.KeyCode.ButtonX,
	Enum.KeyCode.ButtonA,
	Enum.KeyCode.ButtonB,
	Enum.KeyCode.ButtonY
)

Be sure to check the UserInputState before doing anything with the input. For example:

if inputState == Enum.UserInputState.Begin then ...
1 Like

Sounds like your CAS bindings are being disabled (hence Cancel enum) when another script (probably corescript) makes bindings to those keys. Since it’s on escape, it might be the corescript binding the controller buttons to the escape menu items.

I was thinking you were using User Input Service at first. :thinking: I don’t usually use Context Action Service, I made my controller emulator using User Input Service so I sadly can’t help out with this.