Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

keyboard.lib

keyboard.lib offers basic keyboard functions


Importing

local keyboard = import("keyboard.lib")

Methods

register_event

function keyboard.register_event(
    on_press: (key: string) -> nil, 
    on_release: (key: string) -> nil
): number?
  • Registers an event
  • Whenever the key is pressed, on_press is called with the name of the key (Roblox Enum key name)
  • Whenever the key is released, on_release is called with the name of the key (Roblox Enum key name)
  • Returns an ID to the keyboard listener

unregister_event

function keyboard.unregister_event(id: number)
  • Unregisters an event
  • Example usage:
local keyboard = import("keyboard.lib")

local enter_pressed = false

local id = keyboard.register_event(function(key: string)
    if key == "Return" then enter_pressed = true end
end, nil)

while true do
    if enter_pressed then
        keyboard.unregister_event(id)
        break
    end
    wait(0.1)
end

is_key_pressed

function is_key_pressed(key: string): boolean
  • Returns whether a key is pressed or not
  • Pass Roblox Enum key name
  • Example usage:
local keyboard = import("keyboard.lib")
local stdio = import("stdio.lib")

if keyboard.is_key_down("X") then
    stdio.out("X is down!")
end

await_key_press

function await_key_press(key: string)
  • Waits for the specified key to be pressed
  • Pass Roblox Enum key name
  • Example usage:
local keyboard = import("keyboard.lib")
local stdio = import("stdio.lib")

keyboard.await_key_press("Space")

stdio.out("Space was pressed!")