keyboard.waitfor([key])function

Waits for any key, or for a specific key, to be pressed asynchronously, meaning it will block only current execution flow but Tasks will still run in background.

Parameters

[key]

An optional string or number representing the key to wait for. See the list of supported key codes.
If this parameter is omitted, this function waits for any key to be pressed.

Return value

This function returns only when a key have been pressed. The key name is returned as a string.

Example

--! luart-extensions import keyboard local console = require "console" local key async(function () console.write("Waiting for a key") while not key do console.write(".") sleep(1000) end end) key = keyboard.waitfor() print("\nYou have pressed the ["..key.."] key")