PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

IsKeyDown

This function returns whether the user is holding down the key associated with the given Enum/KeyCode. It returns true if the specified key is pressed or false if it is not pressed.

This can be used to check if a specific key, such as the space bar, is being pressed. For example:

local UserInputService = game:GetService("UserInputService")

local spaceHeld = UserInputService:IsKeyDown(Enum.KeyCode.Space)

To retrieve a list of all keys pressed by the user, use the UserInputService/GetKeysPressed function.

Since UserInputService is client-side only, this function can only be used in a LocalScript.

See also

  • UserInputType/IsGamepadButtonDown - A similar event with a different use: To check if a given Enum/KeyCode|button on a Enum/UserInputType|gamepad is pressed.

Parameters

Name Type Default Description

The Enum/KeyCode of the the key

Returns

Return Type Summary

Whether the specified key is being held down


Code Samples


Special Action on Key Combo Press

This example uses the UserInputService/IsKeyDown function to create different behaviors when a shift key is held down than when a shift key is not held down when user input UserInputBegan|begins.

The local function IsShiftKeyDown() returns whether the left or right shift Enum/KeyCode/keys are pressed.