local d={}function d.GetActionInput(d,y)local I="\110\105\108"local t={Zero="\048";One="\049",Two="\050",Three="\051",Four="\052";Five="\053",Six="\054";Seven="\055";Eight="\056",Nine="\057",MouseButton1="\077\066\049",MouseButton2="\077\066\050";MouseButton3="\077\066\051";Return="\069\110\116\101\114",Slash="\047";Tilde="~";Backquote="\096"}if actions[y]then local d,t=actions[y].Primary,actions[y].Secondary if d then I=d.Name elseif t then I=t.Name end end if t[I]then I=t[I]end return string.upper(I)end if not initialized then local y=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")d.KeybindChanged=y.Event actionBegan=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")actionEnded=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")d.ActionBegan=actionBegan.Event d.ActionEnded=actionEnded.Event local I=PLAYER_DATA:WaitForChild(PLAYER.Name)local t=I:WaitForChild("\075\101\121\098\105\110\100\115")local function Z(d,I,t)local Z,a if I then local d,y=string.match(I,"\040\046-\041\037\046\040\046\043\041")if d and y then Z=Enum[d][y]end end if t then local d,y=string.match(t,"\040\046-\041\037\046\040\046\043\041")if d and y then a=Enum[d][y]end end RegisterAction(d,Z,a)y:Fire(d)end local function a(d)local y=d.Name local I=d.Value if string.match(I,"\059")then local d,t=string.match(I,"\040\046-\041\059\040\046\043\041")if d and t then Z(y,d,t)elseif d then Z(y,d)elseif t then Z(y,nil,t)end else Z(y,I)end end t.ChildAdded:connect(function(d)d.Changed:connect(function()a(d)end)RunService.Stepped:wait()a(d)end)repeat RunService.Stepped:wait()until#t:GetChildren()>0 for d,y in pairs(t:GetChildren())do y.Changed:connect(function()a(y)end)a(y)end initialized=true end return d
-- module

local INPUT = {}

function INPUT.GetActionInput(self, action)
	local input = "nil"

	local replacements = {
		Zero = "0",
		One = "1",
		Two = "2",
		Three = "3",
		Four = "4",
		Five = "5",
		Six = "6",
		Seven = "7",
		Eight = "8",
		Nine = "9",

		MouseButton1 = "MB1",
		MouseButton2 = "MB2",
		MouseButton3 = "MB3",
		Return = "Enter",
		Slash = "/",
		Tilde = "~",
		Backquote = "`",
	}

	if actions[action] then
		local primary, secondary = actions[action].Primary, actions[action].Secondary

		if primary then
			input = primary.Name
		elseif secondary then
			input = secondary.Name
		end
	end

	if replacements[input] then
		input = replacements[input]
	end

	return string.upper(input)
end

if not initialized then
	local keybindChanged = Instance.new("BindableEvent")
	INPUT.KeybindChanged = keybindChanged.Event

	actionBegan = Instance.new("BindableEvent")
	actionEnded = Instance.new("BindableEvent")

	INPUT.ActionBegan = actionBegan.Event
	INPUT.ActionEnded = actionEnded.Event

	-- register actions

	local playerData = PLAYER_DATA:WaitForChild(PLAYER.Name)
	local keybinds = playerData:WaitForChild("Keybinds")

	local function Register(action, bindP, bindS)
		local primary, secondary
		if bindP then
			local A, B = string.match(bindP, "(.-)%.(.+)")

			if A and B then
				primary = Enum[A][B]
			end
		end
		if bindS then
			local A, B = string.match(bindS, "(.-)%.(.+)")

			if A and B then
				secondary = Enum[A][B]
			end
		end

		RegisterAction(action, primary, secondary)
		keybindChanged:Fire(action)
	end

	local function Handle(keybind)
		local action = keybind.Name
		local bind = keybind.Value

		if string.match(bind, ";") then
			local bindP, bindS = string.match(bind, "(.-);(.+)")

			if bindP and bindS then
				Register(action, bindP, bindS)
			elseif bindP then
				Register(action, bindP)
			elseif bindS then
				Register(action, nil, bindS)
			end
		else
			Register(action, bind)
		end
	end

	keybinds.ChildAdded:connect(function(keybind)
		keybind.Changed:connect(function()
			Handle(keybind)
		end)

		RunService.Stepped:wait()
		Handle(keybind)
	end)

	repeat
		RunService.Stepped:wait()
	until #keybinds:GetChildren() > 0

	for _, keybind in pairs(keybinds:GetChildren()) do
		keybind.Changed:connect(function()
			Handle(keybind)
		end)

		Handle(keybind)
	end

	initialized = true
end

return INPUT
