Skip to content

Keyboard

The Keyboard represents the keyboard inputs for the player.


Obtain Keyboard

1
local keyboard = userInput:Get("Keyboard")

Methods

IsDown(keyCode)

Returns true|false if the key is down.

1
2
3
if (keyboard:IsDown(Enum.KeyCode.W)) then
    -- W key down
end

AreAllDown(keyCodes...)

Returns true|false if all keys passed are down.

1
2
3
if (keyboard:AreAllDown(Enum.KeyCode.W, Enum.KeyCode.LeftShift)) then
    -- LeftShift + W keys down
end

AreAnyDown(keyCodes...)

Returns true|false if any keys passed are down.

1
2
3
if (keyboard:AreAnyDown(Enum.KeyCode.W, Enum.KeyCode.Up)) then
    -- W or Up Arrow down
end

Events

KeyDown

Fires when a key is pressed.

1
2
3
keyboard.KeyDown:Connect(function(keyCode)
    print(keyCode, "down")
end)

KeyUp

Fires when a key is released.

1
2
3
keyboard.KeyUp:Connect(function(keyCode)
    print(keyCode, "up")
end)