Keyboard
This peripheral is responsible for handling keyboard input.
- Version: v1.0.0
- Available since: LIKO-12 v0.6.0
- Last updated in: LIKO-12 v0.8.0
Methods:
Keyboard.isKDown
Checks whether a certain key is down.
Checks whether a certain key is down.
Check Enums/KeyConstants.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
down = Keyboard.isKDown(key, ...)
Arguments:
- <key> (string): A key to check.
- ... (string): Additional keys to check.
Returns:
- down (boolean): True if any supplied key is down, false if not.
Keyboard.keyrepeat
Enables or disables key repeat.
Enables or disables key repeat. It is disabled 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
than calling this function.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
Usages:
1. Disable/Enable key repeat:
Keyboard.keyrepeat(state)
Arguments:
- <state> (boolean): Whether repeat keypress events should be enabled when a key is held down.
2. Get the current key repeat state:
state = Keyboard.keyrepeat()
Returns:
- state (boolean): Whether repeat keypress events should be enabled when a key is held down.
Keyboard.keytoscancode
Gets the hardware scancode corresponding to the given key.
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.
Check Enums/Scancodes and Enums/KeyConstants.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
scancode = Keyboard.keytoscancode(key)
Arguments:
- <key> (string): The key to get the scancode from.
Returns:
- scancode (string): The scancode corresponding to the given key, or "unknown" if the given key has no known physical representation on the current system.
Keyboard.scancodetokey
Gets the key corresponding to the given hardware scancode.
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.
Check Enums/Scancodes and Enums/KeyConstants.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
key = Keyboard.scancodetokey(scancode)
Arguments:
- <scancode> (string): The scancode to get the key from.
Returns:
- key (string): The key corresponding to the given scancode, or "unknown" if the scancode doesn't map to a KeyConstant on the current system.
Keyboard.textinput
Enables the text input, and shows the onscreen keyboard for the mobile users.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
Usages:
1. Disable/Enable textinput:
Keyboard.textinput(state)
Arguments:
- <state> (boolean): True to enable the input, False to disable it.
2. Get the current textinput state:
state = Keyboard.textinput()
Returns:
- state (boolean): True if the textinput is enabled, false is the text input is disabled.
Events:
Please note that the example functions won't be called automatically, there must be some kind of an events handler for CPU.pullEvent, check if the LIKO-12 OS you're using has one.
keypressed
Triggered when a keyboard button is pressed.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
function _keypressed(key, scancode, isrepeat)
--Content run when the event is triggered
end
Arguments:
- key (string): The character/id of the pressed key.
- scancode (string): The scancode representing the key.
- isrepeat (boolean): Whether this keypress event is a repeat. The delay between key repeats depends on the user's system settings.
keyreleased
Triggered when a keyboard button is released.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
function _keyreleased(key, scancode)
--Content run when the event is triggered
end
Arguments:
- key (string): The character/id of the released key.
- scancode (string): The scancode representing the key.
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.
- Available since: Keyboard: v1.0.0, LIKO-12: v0.6.0
- Last updated in: Keyboard: v1.0.0, LIKO-12: v0.6.0
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)
--Content run when the event is triggered
end
Arguments:
- text (string): The ASCII encoded text.