UserInputService doesnt recognize mouse as keycode

At first time, I met this problem when I was trying to get mouse input through UserInputService.InputBegan signal.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then
		return nil
	end
	
	print(input.KeyCode)	 -- Output: Enum.KeyCode.Unknown
end)

But keycode enum has enums for mouse input

Documentation evidence:
https://create.roblox.com/docs/reference/engine/enums/KeyCode

Code editor evidence:

I recorded the following video to visualize the problem:

Here’s my beta features. I dont expect the most of them to help you, but I have listed all of them:

  1. Dragger QoL Improvements
  2. Improved UIStrokes
  3. Live Animation Creator
  4. New Luau typesolver
  5. Next Gen Studio Preview
  6. Multi-line Command Bar
  7. Scripts are Non-strict by default
  8. Texture generator
  9. UIDragDetectors

Expected behavior

I expect UserInputService.InputBegan signal to support any keycode enum, both mouse and any other input that have its own keycode enum.

Enum.UserInputType.MouseButton1

Hope that helps!

1 Like

its not a keycode its a userinputtype

so you need to do

Enum.UserInputType.MouseButton1

1 Like

Hi,

Thanks for the report. As of now, the mouse keycodes are primarily meant to be used with our new Input Action System and do not get classified in UserInputService events in the KeyCode property of an InputObject. To do this, please use the UserInputType property like other users have suggested. Let us know if you encounter any issues!

1 Like

Thanks to @2_rafael2 and @efsane14010 for response. I was confused when I saw that UserInputServicd.InputBegan input parameter does support mouse besides theres enums for mouse buttons.
I did research and found something in InputObject documentation:

Note that an InputObject corresponding to Enum.UserInputType.MouseButton1 (left click) and Enum.UserInputType.MouseButton2 (right click) supplied from an InputBegan callback will not have its Delta or Position updated once created, except for when the mouse input ends. In order to get updated positions for mouse inputs, you must instead reference an InputObject from an InputChanged callback, or call GetMouseLocation(). However, any InputObjects corresponding to touch inputs will have their delta and position updated every frame throughout their lifetime.

Here’s link to the original documentation
https://create.roblox.com/docs/reference/engine/classes/InputObject

1 Like