UserInputService
Methods
IsKeyDown
Returns whether a certain key is being held down.
UserInputService:IsKeyDown(KeyCode: Enum.KeyCode): BooleanParameters
KeyCode: Enum.KeyCodeThe Enum.KeyCode of the keyReturns
BooleanWhether the specified key is being held down or not.This method returns true if the specified key is held down, otherwise it returns false.
Examples
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function() if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then print("Left Shift") endend)Events
InputBegan
Fires whenever the Player interacts with an input device.
UserInputService.InputBegan(Input: InputObject, GameProcessedEvent: Boolean)Parameters
Input: Input ObjectAn Input object which contains information about the user's input.GameProcessedEvent: BooleanWhether the Engine observed an action and acted on it. If a button was touched or clicked from this input, GameProcessedEvent will be true.Examples
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent) if GameProcessedEvent then print("Game Processed Event") end
if Input.KeyCode == Enum.KeyCode.R then print("R") endend)InputEnded
Fires whenever the Player stops interacting with an input device.
UserInputService.InputEnded(Input: InputObject, GameProcessedEvent: Boolean)Parameters
Input: Input ObjectAn Input object which contains information about the user's input.GameProcessedEvent: BooleanWhether the Engine observed an action and acted on it. If a button was touched or clicked from this input, GameProcessedEvent will be true.Examples
local UserInputService = game:GetService("UserInputService")
UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent) if GameProcessedEvent then print("Game Processed Event") end
print("Input Ended.")end)Vortex Studio 0.3.4 notes
The service is available in a LocalScript and absent in a normal server
Script. InputBegan:Once and InputBegan:Wait both delivered a right-mouse
button input in a LocalScript. Ordinary InputBegan:Connect delivered keyboard
keys (S, A, W, and Space) and mouse buttons; mouse buttons use
Enum.KeyCode.Unknown. Both processed and unprocessed input were observed.
IsKeyDown is available. It returned true for the keyboard key currently
being pressed and false for mouse-button events.
The tested 0.3.4 client reported KeyboardEnabled=true, MouseEnabled=true,
GamepadEnabled=false, and TouchEnabled=false.
InputEnded is connectable in a LocalScript and delivered both keyboard and
mouse-button releases. InputChanged reads as nil and cannot be connected.
GetMouseLocation is unavailable, while MouseBehavior and
MouseIconEnabled read as nil. These results were revalidated in 0.3.4.