2021-01-14 18:19:22 +00:00
|
|
|
---
|
|
|
|
module: [kind=event] char
|
|
|
|
see: key To listen to any key press.
|
|
|
|
---
|
|
|
|
|
2023-03-15 21:52:13 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
|
|
|
|
|
2023-10-11 07:00:07 +00:00
|
|
|
SPDX-License-Identifier: MPL-2.0
|
2023-03-15 21:52:13 +00:00
|
|
|
-->
|
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
The [`char`] event is fired when a character is typed on the keyboard.
|
2021-01-14 18:19:22 +00:00
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
The [`char`] event is different to a key press. Sometimes multiple key presses may result in one character being
|
2021-01-14 18:19:22 +00:00
|
|
|
typed (for instance, on some European keyboards). Similarly, some keys (e.g. <kbd>Ctrl</kbd>) do not have any
|
2023-08-24 09:48:30 +00:00
|
|
|
corresponding character. The [`key`] should be used if you want to listen to key presses themselves.
|
2021-01-14 18:19:22 +00:00
|
|
|
|
|
|
|
## Return values
|
2023-08-24 09:48:30 +00:00
|
|
|
1. [`string`]: The event name.
|
|
|
|
2. [`string`]: The string representing the character that was pressed.
|
2021-01-14 18:19:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
Prints each character the user presses:
|
2023-01-16 22:53:58 +00:00
|
|
|
|
2021-01-14 18:19:22 +00:00
|
|
|
```lua
|
|
|
|
while true do
|
2023-01-16 22:53:58 +00:00
|
|
|
local event, character = os.pullEvent("char")
|
|
|
|
print(character .. " was pressed.")
|
2021-01-14 18:19:22 +00:00
|
|
|
end
|
|
|
|
```
|