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
EventFired when a key is pressed.
keyboard.KeyDown:Connect(function(key: KeyCode)
print("Key pressed", key)
end)
KeyUp
EventFired when a key is released.
keyboard.KeyUp:Connect(function(key: KeyCode)
print("Key released", key)
end)
Functions
new
Constructs a new keyboard input capturer.
local keyboard = Keyboard.new()
IsKeyDown
Keyboard:
IsKeyDown
(
keyCode:
Enum.KeyCode
) →
boolean
Check if the given key is down.
local w = keyboard:IsKeyDown(Enum.KeyCode.W)
if w then ... end
AreKeysDown
Keyboard:
AreKeysDown
(
keyCodeOne:
Enum.KeyCode
,
keyCodeTwo:
Enum.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
(
keyCodeOne:
Enum.KeyCode
,
keyCodeTwo:
Enum.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.