I’ve created this simple module to help with mapping Keybinds. This would be useful for combat games and any other games that need remappable Keybinds. This is my first module I’ve posted on here so I’d really appreciate feedback on how I could improve it.
Here’s the pastebin
ChangeKeyBind
ChangeKeyBind(name, newKeyCode)
Rebinds an existing keybind to a new key.
UnbindKeybind
UnbindKeybind(name)
Removes a keybind by name.
PauseKeybind
PauseKeybind(name)
Temporarily disables the keybind without removing it.
UnPauseKeybind
UnPauseKeybind(name)
Re-enables a previously paused keybind.
CheckKeybind
CheckKeybind(name)
Returns the current Enum.KeyCode for the keybind (or nil if not found).
SetKeyDownCallback
SetKeyDownCallback(name, callback)
Sets the function to run when the key is pressed.
SetKeyUpCallback
SetKeyUpCallback(name, callback)
Sets the function to run when the key is released.
FireKeybindDown
FireKeybindDown(name)
Manually triggers the key down callback for testing/debugging.
FireKeybindUp
FireKeybindUp(name)
Manually triggers the key up callback.
ActivateListener
ActivateListener()
Starts listening for key input events using UserInputService.InputBegan and InputEnded.
You must call this to begin detecting inputs!
DeactivateListener
DeactivateListener()
Disconnects the listeners and cleans up.
GetAllKeybinds
GetAllKeybinds()
Returns the internal keybind table.
SETTINGS
Inside the module:
lua
CopyEdit
SETTINGS = {
WARN = false -- Set to true to enable warnings for missing keybinds or paused keys
}
When WARN = true, invalid operations like rebinding nonexistent keys or firing paused keybinds will trigger a warn().
__
Example Pattern
KeybindHandler.BindKeyBind("Inventory", Enum.KeyCode.I)
KeybindHandler.SetKeyDownCallback("Inventory", function()
print("Opening inventory...")
end)
KeybindHandler.ActivateListener()