Skip to content

Keybinds Manager API

# Via Globals (preferred)
var km = Globals.keybinds_manager
# Check if available (for compatibility)
if Globals.keybinds_manager:
var km = Globals.keybinds_manager

register_external_bind(mod_id: String, definition: Dictionary) -> bool

Section titled “register_external_bind(mod_id: String, definition: Dictionary) -> bool”

Register a keybind for your mod.

Parameters:

  • mod_id: Your mod’s unique identifier (e.g., "my_cool_mod")
  • definition: A dictionary describing the keybind

Returns: true if registration succeeded, false otherwise

Example:

var km = Globals.keybinds_manager
km.register_external_bind("my_mod", {
"id": "my_mod.open_menu",
"display_name": "Open My Menu",
"description": "Opens the custom menu for My Mod",
"category": "My Mod",
"default_binding": {
"type": "key",
"keycode": KEY_M,
"ctrl": true
},
"allow_rebind": true,
"context": km.Context.GLOBAL
})
FieldTypeRequiredDescription
idStringUnique namespaced identifier (e.g., "my_mod.action_name")
display_nameStringHuman-readable name (defaults to id)
descriptionStringTooltip text describing the action
categoryStringGrouping in settings UI (defaults to “General”)
default_bindingDictionaryThe default key/mouse binding
allow_rebindboolWhether user can change this (defaults to true)
contextintWhen bind is active (defaults to GLOBAL)
FieldTypeDescription
typeString"key" or "mouse"
keycodeintGodot KEY_* constant (for type=key)
buttonintMOUSE_BUTTON_* constant (for type=mouse)
ctrlboolCtrl modifier required
altboolAlt modifier required
shiftboolShift modifier required
metaboolMeta/Win modifier required
enum Context {
GLOBAL, # Always active (when not in text field)
IN_GAME, # Only when playing (not in menus)
PALETTE_OPEN, # Only when command palette is open
TEXT_FOCUS # Only when text field has focus
}

connect_bind(mod_id: String, bind_id: String, target: Object, method: String)

Section titled “connect_bind(mod_id: String, bind_id: String, target: Object, method: String)”

Connect a callback to be called when the keybind triggers.

km.connect_bind("my_mod", "my_mod.open_menu", self, "_on_open_menu")
func _on_open_menu() -> void:
# Handle the keybind
my_menu.show()

disconnect_bind(mod_id: String, bind_id: String, target: Object, method: String)

Section titled “disconnect_bind(mod_id: String, bind_id: String, target: Object, method: String)”

Disconnect a previously connected callback.


Connect to these signals for global notifications:

SignalParametersDescription
bind_triggered(bind_id: String)Bind IDEmitted when any bind triggers
bind_registered(bind_id: String)Bind IDEmitted when bind is registered
bind_unregistered(bind_id: String)Bind IDEmitted when bind is removed
binding_changed(bind_id: String, new_binding: Dictionary)Bind ID + bindingEmitted when user rebinds
conflict_detected(bind_id1: String, bind_id2: String)Two conflicting IDsEmitted on conflict

Example:

km.bind_triggered.connect(_on_any_bind_triggered)
func _on_any_bind_triggered(bind_id: String) -> void:
if bind_id == "my_mod.open_menu":
_open_my_menu()

get_binding(bind_id: String) -> Dictionary

Section titled “get_binding(bind_id: String) -> Dictionary”

Get the current effective binding (user override or default).

Get all registered keybinds.

get_binds_by_category(category: String) -> Array[Dictionary]

Section titled “get_binds_by_category(category: String) -> Array[Dictionary]”

Get keybinds in a specific category.

Get all category names.

Get list of current keybind conflicts.


set_binding(bind_id: String, new_binding: Dictionary) -> bool

Section titled “set_binding(bind_id: String, new_binding: Dictionary) -> bool”

Set a custom binding (user override). Returns false if bind doesn’t exist or doesn’t allow rebinding.

Reset a keybind to its default.

Reset all keybinds to defaults.


unregister_external_bind(mod_id: String, bind_id: String)

Section titled “unregister_external_bind(mod_id: String, bind_id: String)”

Remove a keybind. Only the mod that registered it can unregister.


get_binding_display_string(bind_id: String) -> String

Section titled “get_binding_display_string(bind_id: String) -> String”

Get human-readable string for a binding (e.g., “Ctrl+M”).

binding_to_display_string(binding: Dictionary) -> String

Section titled “binding_to_display_string(binding: Dictionary) -> String”

Convert any binding dictionary to display string.

binding_from_event(event: InputEvent) -> Dictionary

Section titled “binding_from_event(event: InputEvent) -> Dictionary”

Create a binding dictionary from an InputEvent (useful for custom rebind UI).


extends Node
const MY_MOD_ID = "my_cool_mod"
func _ready() -> void:
# Wait for Taj's Mod to initialize
call_deferred("_register_keybinds")
func _register_keybinds() -> void:
var km = Globals.keybinds_manager
if not km:
push_warning("KeybindsManager not available")
return
# Register our keybind
km.register_external_bind(MY_MOD_ID, {
"id": "my_cool_mod.toggle_overlay",
"display_name": "Toggle Overlay",
"description": "Shows or hides the custom overlay",
"category": "My Cool Mod",
"default_binding": {
"type": "key",
"keycode": KEY_O,
"ctrl": true,
"shift": true
},
"allow_rebind": true,
"context": km.Context.GLOBAL
})
# Connect callback
km.connect_bind(MY_MOD_ID, "my_cool_mod.toggle_overlay", self, "_toggle_overlay")
print("My Cool Mod: Registered keybind (Ctrl+Shift+O)")
func _toggle_overlay() -> void:
# Your action here
$Overlay.visible = !$Overlay.visible
func _exit_tree() -> void:
# Clean up when mod unloads
var km = Globals.keybinds_manager
if km:
km.unregister_external_bind(MY_MOD_ID, "my_cool_mod.toggle_overlay")