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
Returns | Name | Description | |
---|---|---|---|
Bind | Binds a function to an Input defined using Register or from the game | ||
Unbind | Unbinds an Input function | ||
Register | Registers a keybinding to a default key | ||
Unregister | Unregisters a keybinding | ||
string | GetKeyIcon | Gets the icon path of a key | |
integer | GetKeyCode | Gets the key code of a key | |
KeyModifier | GetModifierKeys | Gets the currently pressed modifier keys | |
table of string | GetMappedKeys | Returns the keys bound to a keybinding | |
ResetBindings | Resets all bound functions by this Package | ||
table | GetScriptingKeyBindings | Returns a table with all Scripting KeyBindings | |
table | GetGameKeyBindings | Returns a table with all Game KeyBindings | |
SetInputEnabled | Toggles Local Player input | ||
SetMouseEnabled | Displays/Hides Mouse Cursor | ||
SetMouseCursor | Sets the current Mouse Cursor type | ||
InputKey | Forces an Input Key event on Local Player | ||
boolean | IsKeyDown | Returns if a key is being pressed | |
boolean | IsMouseEnabled | ||
boolean | IsInputEnabled |
Bind
Binds a function to an Input defined using Register
or from the game
Input.Bind(binding_name, input_event, callback)
Type | Parameter | Default | Description |
---|---|---|---|
string | binding_name | The keybinding id | |
InputEvent | input_event | Which event to register (Released/Pressed) | |
function | callback | The function to trigger |
Unbind
Unbinds all Input functions related to the given binding_name and input_event
Input.Unbind(binding_name, input_event)
Type | Parameter | Default | Description |
---|---|---|---|
string | binding_name | The keybinding id | |
InputEvent | input_event | Which event to register (Released/Pressed) |
Register
Registers a keybinding to a default key
Input.Register(binding_name, key_name)
Unregister
Unregisters a keybinding
Input.Unregister(binding_name, key_name)
GetKeyIcon
Gets the icon path of a key
— Returns string.
local ret = Input.GetKeyIcon(key_name, dark_mode?)
GetKeyCode
Gets the key code of a key
— Returns integer.
local ret = Input.GetKeyCode(key_name)
Type | Parameter | Default | Description |
---|---|---|---|
string | key_name |
GetModifierKeys
Gets the currently pressed modifier keys.
Use bit-wise operators likemodifier & 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)
Type | Parameter | Default | Description |
---|---|---|---|
string | binding_name | The 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)
Type | Parameter | Default | Description |
---|---|---|---|
boolean | enable_input |
SetMouseEnabled
Displays/Hides Mouse Cursor
Input.SetMouseEnabled(is_enabled)
Type | Parameter | Default | Description |
---|---|---|---|
boolean | is_enabled |
SetMouseCursor
Sets the current Mouse Cursor type
Input.SetMouseCursor(cursor_type)
Type | Parameter | Default | Description |
---|---|---|---|
CursorType | cursor_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?)
Type | Parameter | Default | Description |
---|---|---|---|
string | key_name | Key Name to input | |
InputEvent | input_event | Which Event to input | |
float | amount_depressed? | 1 | The amount pressed |
IsKeyDown
Returns if a key is being pressed
— Returns boolean (if the key is pressed).
local ret = Input.IsKeyDown(key_name)
Type | Parameter | Default | Description |
---|---|---|---|
string | key_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
Name | Description | |
---|---|---|
KeyBindingChange | A key binding has been changed through the settings | |
KeyDown | A keyboard key is being pressed | |
KeyPress | A keyboard key has been pressed | |
KeyUp | A keyboard key has been released | |
MouseDown | A mouse button has been pressed / is being pressed | |
MouseUp | A mouse button has been released | |
MouseEnable | When mouse cursor is displayed/hidden | |
MouseMove | Called when the mouse moves | |
MouseScroll | Called 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)
Type | Argument | Description |
---|---|---|
string | binding_name | The keybinding id |
string | key | The new key associated |
float | scale | The 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)
Type | Argument | Description |
---|---|---|
string | key_name | The key pressed |
float or nil | delta | The 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)
Type | Argument | Description |
---|---|---|
string | key_name | The key pressed |
float or nil | delta | The 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)
Type | Argument | Description |
---|---|---|
string | key_name | The key pressed |
float or nil | delta | The 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)
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)
MouseEnable
When mouse cursor is displayed/hidden
Input.Subscribe("MouseEnable", function(is_enabled)
-- MouseEnable was called
end)
Type | Argument | Description |
---|---|---|
boolean | is_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)
MouseScroll
Called when the mouse scrolls
Input.Subscribe("MouseScroll", function(mouse_x, mouse_y, delta)
-- MouseScroll was called
end)
⌨️ Key Names
List of all keys names returned in Key/Mouse events.
▶️ Function Keys
Key Name | Description |
---|---|
F1 | Function one |
F2 | Function two |
F3 | Function three |
F4 | Function four |
F5 | Function five |
F6 | Function six |
F7 | Function seven |
F8 | Function eight |
F9 | Function nine |
F10 | Function ten |
F11 | Function eleven |
F12 | Function twelve |
▶️ Alphanumerical keys
Key Name | Description |
---|---|
A | Letter A |
B | Letter B |
C | Letter C |
D | Letter D |
E | Letter E |
F | Letter F |
G | Letter G |
H | Letter H |
I | Letter I |
J | Letter J |
K | Letter K |
L | Letter L |
M | Letter M |
N | Letter N |
O | Letter O |
P | Letter P |
Q | Letter Q |
R | Letter R |
S | Letter S |
T | Letter T |
U | Letter U |
V | Letter V |
W | Letter W |
X | Letter X |
Y | Letter Y |
Z | Letter Z |
▶️ Special keys
Key Name | Description |
---|---|
Escape | Escape |
Tab | Tab |
Tilde | ~ |
ScrollLock | Scroll lock |
Pause | Pause |
BackSpace | BackSpace |
One | One |
Two | Two |
Three | Three |
Four | Four |
Five | Five |
Six | Six |
Seven | Seven |
Eight | Eight |
Nine | Nine |
Zero | Zero |
Underscore | _ |
Equals | = |
Backslash | |
LeftBracket | [ |
RightBracket | ] |
Enter | Enter or Numpad enter |
CapsLock | Caps lock |
Semicolon | ; |
Quote | ‘ |
LeftShift | Left shift |
Comma | , |
Period | . |
Slash | / |
RightShift | Right Shif |
LeftControl | Left control |
LeftAlt | Left alt |
SpaceBar | Space bar |
RightAlt | Right alt |
RightControl | Right control |
Left | Left |
Up | Up |
Down | Down |
Right | Right |
Home | Home |
End | End |
Insert | Insert |
PageUp | Page up |
Delete | Delete |
PageDown | Page down |
NumLock | Num lock |
Divide | Numpad / |
Multiply | Numpad * |
Subtract | Numpad - |
Add | Numpad + |
PageDown | Page down |
NumPadOne | Numpad one |
NumPadTwo | Numpad two |
NumPadThree | Numpad three |
NumPadFour | Numpad four |
NumPadFive | Numpad five |
NumPadSix | Numpad six |
NumPadSeven | Numpad seven |
NumPadEight | Numpad eight |
NumPadNine | Numpad nine |
NumPadZero | Numpad zero |
Decimal | Numpad decimal |
▶️ Mouse
Key Name | Description |
---|---|
LeftMouseButton | Left mouse button |
RightMouseButton | Right mouse button |
MiddleMouseButton | Middle mouse button |
ThumbMouseButton | Primary mouse thumb button |
ThumbMouseButton2 | Secondary mouse thumb button |
MouseScrollUp | Mouse wheel scrolling up |
MouseScrollDown | Mouse wheel scrolling down |
MouseX | Mouse movement on the X axis |
MouseY | Mouse movement on the Y axis |