The RegisterKeyBind function is used to bind a key on the keyboard to a Lua function.

Callbacks registered with this function are only executed when either the game or the debug console is in focus.

Parameters (overload #1)

#TypeSub TypeInformation
1tableKeyKey to bind
2functionCallback to execute when the key is hit on the keyboard

Parameters (overload #2)

#TypeSub TypeInformation
1integerKey to bind, use the 'Key' table
2tableModifierKeysModifier keys required alongside the 'Key' parameter
3functionCallback to execute when the key is hit on the keyboard

Example (overload #1)

RegisterKeyBind(Key.O, function()
    print("Key 'O' hit.\n")

Example (overload #2)

RegisterKeyBind(Key.O, {ModifierKey.CONTROL, ModifierKey.ALT}, function()
    print("Key 'CTRL + ALT + O' hit.\n")

Advanced Example (overload #1)

This registers a key bind with a callback that does nothing unless there are no widgets currently open

local AnyWidgetsOpen = false

RegisterHook("/Script/UMG.UserWidget:Construct", function()
    AnyWidgetsOpen = true

RegisterHook("/Script/UMG.UserWidget:Destruct", function()
    AnyWidgetsOpen = false

RegisterKeyBind(Key.B, function()
    if AnyWidgetsOpen then return end
    print("Key 'B' hit, while no widgets are open.\n")