ContextActionService BindInput Method Firing When Input Not Pressed

When binding actions to Left Shift and C using ContextActionService, I get unwanted function fires when pressing these keys in this sequence - hold Left Shift, hold C, release Left Shift. It will produce an extra and unwanted “Begin” InputState from the C key, even though it hasn’t been released. Here’s the script that causes the issue and the resulting output:

local contextActionService = game:GetService("ContextActionService")

local function crouch (actionName:string, inputState:Enum.UserInputState, inputObject:InputObject)
	print("Crouch "..tostring(inputState))
end

local function sprint (actionName, inputState, inputObject)
	print("Sprint "..tostring(inputState))
end

contextActionService:BindAction("Crouch", crouch, false, Enum.KeyCode.C)
contextActionService:BindAction("Sprint", sprint, false, Enum.KeyCode.LeftShift)

image

Expected behavior

BindFunction should only fire its specified function when the InputState of an input changes. There should be a “Begin” InputState only when a button is pressed down, and an “End” InputState only when the button is released.

Thanks for the report! We’ll look into it.

1 Like

Some newly discovered information regarding this topic (you can go to this forum post to see the reply, but I’ll summarize here what was said):

Summary:
This issue seems to be related to Left Shift being a “modifier key” (see InputObject:IsModifierKeyDown()). I’m not sure if this extra InputState is intended, but personally, I would rather it didn’t happen. Using the IsModifierKeyDown method does not solve the problem, because I still want to perform the action bound to C whether a modifier key is down or not. Hopefully this information helps.

@Marked4Destruction , we rolled out a change that should improve handling of the modifier keys. Can you please check if you see the expected event sequence?

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