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)
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.
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?