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

GetMouseButtonsPressed

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.

Since UserInputService only runs client-side, this function will only work when used in a LocalScript.

Returns

Return Type Summary

An array of /InputObjects that corresponds to all the mouse buttons being currently pressed down.


Code Samples


UserInputService:GetMouseButtonsPressed

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)