How do I detect UserInputType and KeyCode?

local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Usages = ReplicatedStorage.Usage
local Keybinds = require(Usages.Client.Keybinds)


local function MainFunction(actionName, InputState, InputObject)
	if actionName == "Portafab" and InputState == Keybinds[actionName].EnumType then
		require(Usages.Tools[tostring(actionName)])("Start", InputObject)
		
	elseif InputState == Keybinds[actionName].EnumType then
		require(Usages.Tools[tostring(actionName)])("Start", InputObject)
		
	end
	
end

ContextActionService.LocalToolEquipped:Connect(function(a)
	ContextActionService:BindAction(a.Name, MainFunction, false, unpack(Keybinds[tostring(a)]))
end)

ContextActionService.LocalToolUnequipped:Connect(function(a)
	ContextActionService:UnbindAction(a.Name)
end)


-- // Keybind
return {
	Portafab = {
		Enum.KeyCode.Z,
		Enum.KeyCode.X,
		Enum.KeyCode.C,
		Enum.UserInputType.MouseButton1,
		
		EnumType = Enum.UserInputState.Begin
	},
	
	["Satchel Charge"] = {
		Enum.UserInputType.MouseButton1,
		Enum.KeyCode.E,
		
		EnumType = Enum.UserInputState.Begin
	},
	
	["Cruise Missile"] = {
		Enum.UserInputType.MouseButton1,

		EnumType = Enum.UserInputState.Begin
	}
}
-- // First Tool
return function (Action, ActionKey)

	local function Key(Keys)

		if Keys.KeyCode then
			return Keys.KeyCode
		elseif Keys.UserInputType then
			return Keys.UserInputType
		end

	end

	if Action == "Start" then
		print(Key(ActionKey))
	else
		return
	end


end

I’m trying to separate keybinds to a specific tools. but the problem is that it only detects KeyCodes not userInputType

everything works it prints out Enum.KeyCode.Z, Enum.KeyCode.X but other than when I try to click a MouseButton1 I get Enum.KeyCode.Unknown

Video: https://gyazo.com/cfe5ac35542ae6e4b9161bbff3dafc36

I’m trying to get:

Enum.KeyCode.Z
Enum.KeyCode.X
Enum.KeyCode.C

AND

Enum.UserInputType.MouseButton1

But the code I have in section 3 block it doesn’t detect UserInputType and I have no idea to do it. I have tried using the Enum properties “EnumType” but it doesn’t work.

Do you use UserInputService? e.g:

key = Enum.KeyCode.Z -- set this to any keycode
mousebuttons = Enum.UserInputType.MouseButton1 -- or whatever is it called
game:GetService("UserInputService").InputBegan:Connect(function(input) -- this will be called every time player will click something
       if input.KeyCode == key then
             -- ...
       elseif input.UserInputType == mousebuttons then
             -- ...
       end
end)

If the code is bad it’s because I am not on roblox studio right now.

No I’m not going to use UserInputService it’s not good for me to use it on a multiple tools.

Personally I use UserInputService on my tools, and it works really great. Let me think of another method.

The method I’m using is ContextActionService it’s really great to use for performances. Which is why I use it and not js that but it lets me add Mobile Button too. But rn i’m trying to find help how to identify UserInputType and KeyCode.

You could use

player:GetMouse().Button1Up:Connect(function()
        --...
        print("Button 1 has been clicked!")
end)

Make sure to send this from Client to Server.