2021-01-14 18:19:22 +00:00
|
|
|
---
|
|
|
|
module: [kind=event] key
|
|
|
|
---
|
|
|
|
|
2023-03-15 21:52:13 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LicenseRef-CCPL
|
|
|
|
-->
|
|
|
|
|
2021-01-14 18:19:22 +00:00
|
|
|
This event is fired when any key is pressed while the terminal is focused.
|
|
|
|
|
|
|
|
This event returns a numerical "key code" (for instance, <kbd>F1</kbd> is 290). This value may vary between versions and
|
|
|
|
so it is recommended to use the constants in the @{keys} API rather than hard coding numeric values.
|
|
|
|
|
|
|
|
If the button pressed represented a printable character, then the @{key} event will be followed immediately by a @{char}
|
|
|
|
event. If you are consuming text input, use a @{char} event instead!
|
|
|
|
|
|
|
|
## Return values
|
2021-01-19 09:20:52 +00:00
|
|
|
1. @{string}: The event name.
|
|
|
|
2. @{number}: The numerical key value of the key pressed.
|
|
|
|
3. @{boolean}: Whether the key event was generated while holding the key (@{true}), rather than pressing it the first time (@{false}).
|
2021-01-14 18:19:22 +00:00
|
|
|
|
|
|
|
## Example
|
|
|
|
Prints each key when the user presses it, and if the key is being held.
|
|
|
|
|
|
|
|
```lua
|
|
|
|
while true do
|
2021-04-28 20:24:27 +00:00
|
|
|
local event, key, is_held = os.pullEvent("key")
|
2021-01-15 09:54:38 +00:00
|
|
|
print(("%s held=%s"):format(keys.getName(key), is_held))
|
2021-01-14 18:19:22 +00:00
|
|
|
end
|
|
|
|
```
|