Skip to main content

Keyboard

This item only works when running on the client. Client

The Keyboard class is part of the Input package.

local Keyboard = require(packages.Input).Keyboard

Properties

KeyDown

Event
Keyboard.KeyDown: Signal<Enum.KeyCode>

Fired when a key is pressed.

keyboard.KeyDown:Connect(function(key: KeyCode)
	print("Key pressed", key)
end)

KeyUp

Event
Keyboard.KeyUp: Signal<Enum.KeyCode>

Fired when a key is released.

keyboard.KeyUp:Connect(function(key: KeyCode)
	print("Key released", key)
end)

Functions

new

Keyboard.new() → Keyboard

Constructs a new keyboard input capturer.

local keyboard = Keyboard.new()

IsKeyDown

Keyboard:IsKeyDown(keyCodeEnum.KeyCode) → boolean

Check if the given key is down.

local w = keyboard:IsKeyDown(Enum.KeyCode.W)
if w then ... end

AreKeysDown

Keyboard:AreKeysDown(
keyCodeOneEnum.KeyCode,
keyCodeTwoEnum.KeyCode
) → boolean

Check if both keys are down. Useful for key combinations.

local shiftA = keyboard:AreKeysDown(Enum.KeyCode.LeftShift, Enum.KeyCode.A)
if shiftA then ... end

AreEitherKeysDown

Keyboard:AreEitherKeysDown(
keyCodeOneEnum.KeyCode,
keyCodeTwoEnum.KeyCode
) → boolean

Check if either of the keys are down. Useful when two keys might perform the same operation.

local wOrUp = keyboard:AreEitherKeysDown(Enum.KeyCode.W, Enum.KeyCode.Up)
if wOrUp then
	-- Go forward
end

Destroy

Keyboard:Destroy() → ()

Destroy the keyboard input capturer.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new keyboard input capturer.\n\n```lua\nlocal keyboard = Keyboard.new()\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Keyboard"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 55,
                "path": "modules/input/Keyboard.lua"
            }
        },
        {
            "name": "IsKeyDown",
            "desc": "Check if the given key is down.\n\n```lua\nlocal w = keyboard:IsKeyDown(Enum.KeyCode.W)\nif w then ... end\n```",
            "params": [
                {
                    "name": "keyCode",
                    "desc": "",
                    "lua_type": "Enum.KeyCode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 72,
                "path": "modules/input/Keyboard.lua"
            }
        },
        {
            "name": "AreKeysDown",
            "desc": "Check if _both_ keys are down. Useful for key combinations.\n\n```lua\nlocal shiftA = keyboard:AreKeysDown(Enum.KeyCode.LeftShift, Enum.KeyCode.A)\nif shiftA then ... end\n```",
            "params": [
                {
                    "name": "keyCodeOne",
                    "desc": "",
                    "lua_type": "Enum.KeyCode"
                },
                {
                    "name": "keyCodeTwo",
                    "desc": "",
                    "lua_type": "Enum.KeyCode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 84,
                "path": "modules/input/Keyboard.lua"
            }
        },
        {
            "name": "AreEitherKeysDown",
            "desc": "Check if _either_ of the keys are down. Useful when two keys might perform\nthe same operation.\n\n```lua\nlocal wOrUp = keyboard:AreEitherKeysDown(Enum.KeyCode.W, Enum.KeyCode.Up)\nif wOrUp then\n\t-- Go forward\nend\n```",
            "params": [
                {
                    "name": "keyCodeOne",
                    "desc": "",
                    "lua_type": "Enum.KeyCode"
                },
                {
                    "name": "keyCodeTwo",
                    "desc": "",
                    "lua_type": "Enum.KeyCode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 99,
                "path": "modules/input/Keyboard.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroy the keyboard input capturer.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 126,
                "path": "modules/input/Keyboard.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "KeyDown",
            "desc": "Fired when a key is pressed.\n```lua\nkeyboard.KeyDown:Connect(function(key: KeyCode)\n\tprint(\"Key pressed\", key)\nend)\n```",
            "lua_type": "Signal<Enum.KeyCode>",
            "tags": [
                "Event"
            ],
            "source": {
                "line": 34,
                "path": "modules/input/Keyboard.lua"
            }
        },
        {
            "name": "KeyUp",
            "desc": "Fired when a key is released.\n```lua\nkeyboard.KeyUp:Connect(function(key: KeyCode)\n\tprint(\"Key released\", key)\nend)\n```",
            "lua_type": "Signal<Enum.KeyCode>",
            "tags": [
                "Event"
            ],
            "source": {
                "line": 45,
                "path": "modules/input/Keyboard.lua"
            }
        }
    ],
    "types": [],
    "name": "Keyboard",
    "desc": "The Keyboard class is part of the Input package.\n\n```lua\nlocal Keyboard = require(packages.Input).Keyboard\n```",
    "realm": [
        "Client"
    ],
    "source": {
        "line": 20,
        "path": "modules/input/Keyboard.lua"
    }
}