Skip to main content

Input

Create custom keybindings and retrieve input information.

🗿Static Class
This is a Static Class. Access it's methods directly with .. It's not possible to spawn new instances.
💂Authority
This static class can be accessed only on 🟧 Client side.

Examples

Client/Index.lua
-- Registers the binding_name 'SpawnMenu' with default key 'Q'
-- This will add 'SpawnMenu' to user KeyBinding Settings automatically
Input.Register("SpawnMenu", "Q")

-- Subscribes for Pressing the key
Input.Bind("SpawnMenu", InputEvent.Pressed, function()
-- Opens the Spawn Menu
end)

-- Subscribes for Releasing the key
Input.Bind("SpawnMenu", InputEvent.Released, function()
-- Closes the Spawn Menu
end)

Static Functions

ReturnsNameDescription
BindBinds a function to an Input defined using Register or from the game
UnbindUnbinds an Input function
RegisterRegisters a keybinding to a default key
UnregisterUnregisters a keybinding
stringGetKeyIconGets the icon path of a key
integerGetKeyCodeGets the key code of a key
KeyModifierGetModifierKeysGets the currently pressed modifier keys
table of stringGetMappedKeysReturns the keys bound to a keybinding
ResetBindingsResets all bound functions by this Package
tableGetScriptingKeyBindingsReturns a table with all Scripting KeyBindings
tableGetGameKeyBindingsReturns a table with all Game KeyBindings
SetInputEnabledToggles Local Player input
SetMouseEnabledDisplays/Hides Mouse Cursor
SetMouseCursorSets the current Mouse Cursor type
InputKeyForces an Input Key event on Local Player
booleanIsKeyDownReturns if a key is being pressed
booleanIsMouseEnabled
booleanIsInputEnabled

Bind

Binds a function to an Input defined using Register or from the game

Input.Bind(binding_name, input_event, callback)
TypeParameterDefaultDescription
stringbinding_nameThe keybinding id
InputEventinput_eventWhich event to register (Released/Pressed)
functioncallbackThe function to trigger

Unbind

Unbinds all Input functions related to the given binding_name and input_event

Input.Unbind(binding_name, input_event)
TypeParameterDefaultDescription
stringbinding_nameThe keybinding id
InputEventinput_eventWhich event to register (Released/Pressed)

Register

Registers a keybinding to a default key

Input.Register(binding_name, key_name)
TypeParameterDefaultDescription
stringbinding_nameThe keybinding id
stringkey_name

Unregister

Unregisters a keybinding

Input.Unregister(binding_name, key_name)
TypeParameterDefaultDescription
stringbinding_nameThe keybinding id
stringkey_name

GetKeyIcon

Gets the icon path of a key

— Returns string.

local ret = Input.GetKeyIcon(key_name, dark_mode?)
TypeParameterDefaultDescription
stringkey_name
booleandark_mode?false

GetKeyCode

Gets the key code of a key

— Returns integer.

local ret = Input.GetKeyCode(key_name)
TypeParameterDefaultDescription
stringkey_name

GetModifierKeys

Gets the currently pressed modifier keys.
Use bit-wise operators like modifier & KeyModifier.LeftShiftDown to know if the left shift is pressed.

— Returns KeyModifier.

local ret = Input.GetModifierKeys()

GetMappedKeys

Returns the keys bound to a keybinding

— Returns table of string (list of all keys).

local ret = Input.GetMappedKeys(binding_name)
TypeParameterDefaultDescription
stringbinding_nameThe keybinding id

ResetBindings

Resets all bound functions by this Package

Input.ResetBindings()

GetScriptingKeyBindings

Returns a table with all Scripting KeyBindings

— Returns table (in the format <code>{ "[BINDING_NAME]" = { "[KEY_01]", "[KEY_02]", ... }, ... }</code>).

local ret = Input.GetScriptingKeyBindings()

GetGameKeyBindings

Returns a table with all Game KeyBindings

— Returns table (in the format <code>{ "[BINDING_NAME]" = { "[KEY_01]", "[KEY_02]", ... }, ... }</code>).

local ret = Input.GetGameKeyBindings()

SetInputEnabled

Toggles Local Player input

Input.SetInputEnabled(enable_input)
TypeParameterDefaultDescription
booleanenable_input

SetMouseEnabled

Displays/Hides Mouse Cursor

Input.SetMouseEnabled(is_enabled)
TypeParameterDefaultDescription
booleanis_enabled

SetMouseCursor

Sets the current Mouse Cursor type

Input.SetMouseCursor(cursor_type)
TypeParameterDefaultDescription
CursorTypecursor_type

InputKey

Forces an Input Key event on Local Player

This won't trigger any Scripting event as it bypass internal validations

Input.InputKey(key_name, input_event, amount_depressed?)
TypeParameterDefaultDescription
stringkey_nameKey Name to input
InputEventinput_eventWhich Event to input
floatamount_depressed?1The amount pressed

IsKeyDown

Returns if a key is being pressed

— Returns boolean (if the key is pressed).

local ret = Input.IsKeyDown(key_name)
TypeParameterDefaultDescription
stringkey_name

IsMouseEnabled

— Returns boolean (if the mouse is visible).

local ret = Input.IsMouseEnabled()

IsInputEnabled

— Returns boolean (if the input is visible).

local ret = Input.IsInputEnabled()

Events

NameDescription
KeyBindingChangeA key binding has been changed through the settings
KeyDownA keyboard key is being pressed
KeyPressA keyboard key has been pressed
KeyUpA keyboard key has been released
MouseDownA mouse button has been pressed / is being pressed
MouseUpA mouse button has been released
MouseEnableWhen mouse cursor is displayed/hidden
MouseMoveCalled when the mouse moves
MouseScrollCalled when the mouse scrolls

KeyBindingChange

A key binding has been changed through the settings
Input.Subscribe("KeyBindingChange", function(binding_name, key, scale)
-- KeyBindingChange was called
end)
TypeArgumentDescription
stringbinding_nameThe keybinding id
stringkeyThe new key associated
floatscaleThe scale input (usually 1 or -1)

KeyDown

A keyboard key is being pressed

Return false to block it
Input.Subscribe("KeyDown", function(key_name, delta)
-- KeyDown was called
end)
TypeArgumentDescription
stringkey_nameThe key pressed
float or nildeltaThe amount depressed in case of this is an Axis input

KeyPress

A keyboard key has been pressed

Return false to block it
Input.Subscribe("KeyPress", function(key_name, delta)
-- KeyPress was called
end)
TypeArgumentDescription
stringkey_nameThe key pressed
float or nildeltaThe amount depressed in case of this is an Axis input

KeyUp

A keyboard key has been released

Return false to block it
Input.Subscribe("KeyUp", function(key_name, delta)
-- KeyUp was called
end)
TypeArgumentDescription
stringkey_nameThe key pressed
float or nildeltaThe amount depressed in case of this is an Axis input

MouseDown

A mouse button has been pressed / is being pressed

Return false to block it
Input.Subscribe("MouseDown", function(key_name, mouse_x, mouse_y)
-- MouseDown was called
end)
TypeArgumentDescription
stringkey_name
floatmouse_x
floatmouse_y

MouseUp

A mouse button has been released

Return false to block it
Input.Subscribe("MouseUp", function(key_name, mouse_x, mouse_y)
-- MouseUp was called
end)
TypeArgumentDescription
stringkey_name
floatmouse_x
floatmouse_y

MouseEnable

When mouse cursor is displayed/hidden
Input.Subscribe("MouseEnable", function(is_enabled)
-- MouseEnable was called
end)
TypeArgumentDescription
booleanis_enabled

MouseMove

Called when the mouse moves
Input.Subscribe("MouseMove", function(cursor_delta_x, cursor_delta_y, mouse_x, mouse_y)
-- MouseMove was called
end)
TypeArgumentDescription
floatcursor_delta_x
floatcursor_delta_y
floatmouse_x
floatmouse_y

MouseScroll

Called when the mouse scrolls
Input.Subscribe("MouseScroll", function(mouse_x, mouse_y, delta)
-- MouseScroll was called
end)
TypeArgumentDescription
floatmouse_x
floatmouse_y
floatdelta

⌨️ Key Names

List of all keys names returned in Key/Mouse events.

▶️ Function Keys

Key NameDescription
F1Function one
F2Function two
F3Function three
F4Function four
F5Function five
F6Function six
F7Function seven
F8Function eight
F9Function nine
F10Function ten
F11Function eleven
F12Function twelve

▶️ Alphanumerical keys

Key NameDescription
ALetter A
BLetter B
CLetter C
DLetter D
ELetter E
FLetter F
GLetter G
HLetter H
ILetter I
JLetter J
KLetter K
LLetter L
MLetter M
NLetter N
OLetter O
PLetter P
QLetter Q
RLetter R
SLetter S
TLetter T
ULetter U
VLetter V
WLetter W
XLetter X
YLetter Y
ZLetter Z

▶️ Special keys

Key NameDescription
EscapeEscape
TabTab
Tilde~
ScrollLockScroll lock
PausePause
BackSpaceBackSpace
OneOne
TwoTwo
ThreeThree
FourFour
FiveFive
SixSix
SevenSeven
EightEight
NineNine
ZeroZero
Underscore_
Equals=
Backslash
LeftBracket[
RightBracket]
EnterEnter or Numpad enter
CapsLockCaps lock
Semicolon;
Quote
LeftShiftLeft shift
Comma,
Period.
Slash/
RightShiftRight Shif
LeftControlLeft control
LeftAltLeft alt
SpaceBarSpace bar
RightAltRight alt
RightControlRight control
LeftLeft
UpUp
DownDown
RightRight
HomeHome
EndEnd
InsertInsert
PageUpPage up
DeleteDelete
PageDownPage down
NumLockNum lock
DivideNumpad /
MultiplyNumpad *
SubtractNumpad -
AddNumpad +
PageDownPage down
NumPadOneNumpad one
NumPadTwoNumpad two
NumPadThreeNumpad three
NumPadFourNumpad four
NumPadFiveNumpad five
NumPadSixNumpad six
NumPadSevenNumpad seven
NumPadEightNumpad eight
NumPadNineNumpad nine
NumPadZeroNumpad zero
DecimalNumpad decimal

▶️ Mouse

Key NameDescription
LeftMouseButtonLeft mouse button
RightMouseButtonRight mouse button
MiddleMouseButtonMiddle mouse button
ThumbMouseButtonPrimary mouse thumb button
ThumbMouseButton2Secondary mouse thumb button
MouseScrollUpMouse wheel scrolling up
MouseScrollDownMouse wheel scrolling down
MouseXMouse movement on the X axis
MouseYMouse movement on the Y axis