Skip to main content

Keyboard

The standard text input method on desktop and laptop devices.

info

For a list of all the buttons enum values, check keyboard enums in the appendix.

Methods:

isKDown

Check whether a certain key or any key of a group is down.

isButtonDown = isKDown(key, ...)
ParameterTypeDefaultNote
keystring⚠️ requiredcheck the keys enum.
...stringvarargsany other keys.
ReturnTypeNote
isButtonDownbooleanif any key from the provided ones was down.

keyrepeat

Enables or disables key repeat. Which is enabled by default.

The interval between repeats depends on the user's system settings.

note

It's better to do if isrepeat then return true end in the keyboard events/callbacks than disabling the feature.

Set the key repeat state

keyrepeat(isEnabled)
ParameterTypeDefaultNote
isEnabledboolean⚠️ required

Get the key repeat state

isEnabled = keyrepeat()
ReturnTypeNote
isEnabledboolean

keytoscancode

Gets the hardware scancode corresponding to the given key.

Unlike key constants, Scancodes are keyboard layout-independent. For example the scancode "w" will be generated if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.

Scancodes are useful for creating default controls that have the same physical locations on on all systems.

scancode = keytoscancode(key)
ParameterTypeDefaultNote
keystring⚠️ required
ReturnTypeNote
scancodestring

scancodetokey

Gets the key corresponding to the given hardware scancode.

Unlike key constants, Scancodes are keyboard layout-independent. For example the scancode "w" will be generated if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.

Scancodes are useful for creating default controls that have the same physical locations on on all systems.

key = scancodetokey(scancode)
ParameterTypeDefaultNote
scancodestring⚠️ required
ReturnTypeNote
keystring

textinput

Enable/Disable the text input and the onscreen keyboard for the mobile users.

Set text input state

textinput(isEnabled)
ParameterTypeDefaultNote
isEnabledboolean⚠️ required

Get the text input state

isEnabled = textinput()
ReturnTypeNote
isEnabledboolean

Events:

_keypressed

Triggered when a keyboard button is pressed.

function _keypressed(key, scancode, isRepeat)
--Logic executed when the event is triggered
end
ParameterTypeNote
keystring
scancodestring
isRepeatbooleanwhether the event was repeated due to the keyrepeat feature or not.

_keyreleased

Triggered when a keyboard button is released.

function _keyreleased(key, scancode)
--Logic executed when the event is triggered
end
ParameterTypeNote
keystring
scancodestring

_textinput

Called when text has been entered by the user. For example if shift-2 is pressed on an American keyboard layout, the text '@' will be generated.

caution

All non ASCII characters are filtered out and replaced with nothing. So in case of non-English input, the event would be triggered with empty strings.

function _textinput(text)
--Logic executed when the event is triggered
end
ParameterTypeNote
textstring