The GetMouseButtonsPressed function returns an array of
InputObject|InputObjects that corresponds to all the mouse buttons being currently pressed down.
To process all mouse buttons currently pressed down, you must iterate through the array returned by the function. For help with this, take a look at the example below.
Note: If no mouse buttons are currently being pressed down when the function is used, it will return an empty array.
UserInputService only runs client-side, this function will only work when used in a
An array of
This example prints the name of all pressed MouseButtons when the
/UserInputService/InputBegan event fires.
local UserInputService = game:GetService("UserInputService") -- InputBegan is a UserInputService event that fires when the player -- begins interacting via a Human-User input device UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) -- Returns an array of the pressed MouseButtons local buttons = UserInputService:GetMouseButtonsPressed() -- Prints the Name of all MouseButtons pressed by printing the name -- of the Enum.UserInputType KeyCode assigned to the pressed button for i in pairs (buttons) do print("The ["..buttons[i].KeyCode.Name .."] key is pressed") end end)