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

LastInputTypeChanged

The LastInputTypeChanged event fires whenever the client changes how they are interacting via a Human-Computer Interface device. (i.e. from MouseMovement to MouseWheel or from Thumbstick1 to Thumbstick2).

To get the value of LastInputType, regardless of whether it has changed, you can use the UserInputService/GetLastInputType function.

As this event only fires locally, it can only be used in a LocalScript.

Parameters

Name Type Default Description

A Enum/UserInputType indicating the last input type.


Code Samples


Hide Mouse During Keyboard Input

This example hides the mouse icon while the player beings using their keyboard, such as to chat or enter text into a TextBox. The mouse icon reappears when the user resumes mouse input.

This uses the UserInputType/LastInputType|LastInputType event to determine when the user begins keyboard input and mouse input - based on the value of the Enum/UserInputType/lastInputType argument.

In order for this example to work as expected, it should be placed in a LocalScript.

local UserInputService = game:GetService("UserInputService")

local mouseInput =
{
	Enum.UserInputType.MouseButton1,
	Enum.UserInputType.MouseButton2,
	Enum.UserInputType.MouseButton3,
	Enum.UserInputType.MouseMovement,
	Enum.UserInputType.MouseWheel	
}

local keyboard = Enum.UserInputType.Keyboard

local function ToggleMouse(lastInputType)
	if lastInputType == keyboard then
		UserInputService.MouseIconEnabled = false
		return
	end
	
	for i, mouse in pairs (mouseInput) do
		if lastInputType == mouse then
			UserInputService.MouseIconEnabled = true
			return
		end
	end
end

UserInputService.LastInputTypeChanged:Connect(ToggleMouse)