For thread safety, this property is not safe to read in an unsynchronized thread.
This function returns an array of
InputObject|InputObjects associated with the keys currently being pressed down.
This array can be iterated through to determine which keys are currently being pressed, using the
To check if a specific key is being pressed, use
UserInputService is client-side only, this function can only be used in a
An array of
Double Jump Key Combo
This example demonstrates how to use the
UserInputService/GetKeysPressed function to create a combo action where the player double jumps when the the player presses actionKey key (Left Shift) + Jump key (Spacebar).
The actionKey variable indicates which key, combined with the Jump key, needs to be pressed for the player to double jump.
When the player presses the Jump key, the
UserInputService/JumpRequest|JumpRequest event is invoked, which is connected to the script’s jumpRequest function. If the Left Shift key is pressed and the player is not already in the middle of a jump, this function sets the canDoubleJump boolean to true.
The example connects the stateChanged function to the
Humanoid/StateChanged|StateChanged event so that the function fires when their
Enum/HumanoidStateType|humanoid’s state changes. If the state changes from Jumping to Freefall, and the canDoubleJump boolean is true, the function makes the player jump again by setting their humanoid’s state back to Jumping using the
The example also uses the canJump boolean variable to determine when the player is in the middle of a jump. Without this variable, the player could press the actionKey + Jump Key (spacebar) to jump endlessly without landing. When the boolean is true, the player is not jumping. If the player is not jumping, jumpRequest() checks if the actionKey is pressed and sets canJump to false. When the player lands, stateChanged() sets the variable to true.