This is a simple input API that allows for functions to be attached to “actions,” unique strings associated with an Enum.KeyCode
or Enum.UserInputType
(or multiple at once).
This was initially part of a third-person melee combat system, but it proved very useful for other projects. I’ve made it public and open-source in case it’s useful to anybody else.
API
The API as of v1.0.1 is very simple, with 2 functions:
ActionHandler.RegisterCallback(actionName: string, state: Enum.UserInputState, callback: () -> ())
-- Registers function `callback` to be called when action `actionName` is triggered with a UserInputState of `state`. `callback` is given no parameters and does not need to return anything.
ActionHandler.Clean()
-- Removes all callbacks.
Quick Example
-- In a client script containing the ActionHandler module:
local ActionHandler = require(script.ActionHandler)
ActionHandler.RegisterCallback("myAction", Enum.UserInputState.Begin, function ()
print("myAction was triggered!")
end)
ActionHandler.RegisterCallback("myAction", Enum.UserInputState.End, function ()
print("myAction was released!")
end)
-- In ActionHandler.Binds:
return {
[Enum.KeyCode.X] = "myAction";
}
Releases
ActionHandler_v1-0-1.rbxm (2.5 KB)