As the title suggests, I want an action to happen when pressing the WASD keys, but I don’t want to unbind the movement part of these keys. I’d also rather not use UserInputService, but if there isn’t really a way around it, let me know.
ContextActionService inherently binds the keys to a specific action, so I do not believe you will be able to achieve this. You should use UserInputService, as you correctly stated.
Use UserInputService as that won’t override any existing keybinds Roblox already uses.
Bumping incase anyone else stumbles on this post…
If your action handler function returns Enum.ContextActionResult.Pass
, then it won’t interrupt other action handler functions, such as Roblox’s default character movement.
Here’s what Roblox’s docs say about it:
(from ContextActionService | Documentation - Roblox Creator Hub)
Action Bindings StackAction bindings behave like a stack: if two actions are bound to the same user input, the most recently bound action handler will be used. If an action handler returns ContextActionResult.Pass, the next most recently bound action handler will be called, and so on until a handler sinks the input (by returning nil or ContextActionResult.Sink). When UnbindAction is called, the action handler is removed from the stack. This stack behavior can be overridden using BindActionAtPriority, where an additional priority parameter after createTouchButton may override the order in which actions are bound (higher before lower).
And here’s some example code:
function MoveAction(actionName, inputState, _inputObject)
print("WASD was pressed!")
-- this line 'passes' the action to the next action handler
-- which will allow the player to move properly
return Enum.ContextActionResult.Pass
end
game.ContextActionService:BindAction("Move", MoveAction, false, Enum.KeyCode.W,
Enum.KeyCode.S, Enum.KeyCode.A, Enum.KeyCode.D)