Overview
Input service is a fully typed module I designed for my personal uses that I figured would be useful for some people. It’s a simple wrapper for context action service that supports custom keybinds, disabling-enabling of bindings, and more. It’s also very simple to set up.
Docs
Creating an action
local InputService = require(path.to.module)
InputService.CreateAction(
"Attack", {
Enum.UserInputType.MouseButton1,
Enum.KeyCode.E
})
Binding to an action
It is important to note that these functions wait for a return. So if you wish to yield, task.spawn().
If you return true, any bindings of a lower priority wont be called.
local PRIORITY = 1
InputService.Bind("Attack", "BindingName", PRIORITY, function(action_name, state, inputObject, gameProcessed)
if gameProcessed then return end
if state == Enum.UserInputState.End then
print("Attack")
end
end)
Unbinding of actions
InputService.Unbind("Attack", "BindingName")
Updating keybinds
InputService.UpdateActionKeys("Attack", {Enum.KeyCode.Q})
Toggling actions active
I use this alot personally. For example if I wanted to have a 2 weapons, instead of having one attack function and checking every time which one is equipped, I would have 2 Actions
, and set which one is active depending on the equipped item.
InputService.SetActionActive("PrimaryAttack", false)
InputService.SetActionActive("SecondaryAttack", true)
Download
You can find the model on roblox here, and if you want to use rojo you can find the code here.