local g="\078\101\120\117\115\085\115\101\114\073\110\112\117\116"local A=.05 local I=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local O=game:GetService("\080\108\117\103\105\110\071\117\105\083\101\114\118\105\099\101")local Y=(require(script.Parent.Parent:WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107\080\114\111\106\101\099\116"))):GetContext(script)local z=Y:GetResource("\066\097\115\101\046\078\101\120\117\115\067\111\110\116\097\105\110\101\114")local q=Y:GetResource("\078\101\120\117\115\073\110\115\116\097\110\099\101\046\069\118\101\110\116\046\078\101\120\117\115\069\118\101\110\116\067\114\101\097\116\111\114")local a=z:Extend()a:SetClassName(g)Y:SetContextResource(a)a.LastInputBeganTimes={}a.LastInputChangedTimes={}a.LastInputEndedTimes={}a.InputBegan=q:CreateEvent()a.InputChanged=q:CreateEvent()a.InputEnded=q:CreateEvent()function a.__new(A)A:InitializeSuper()A.Name=g A.__ContextEvents={}A.LastInputBeganTimes={}A.LastInputChangedTimes={}A.LastInputEndedTimes={}A.InputBegan=q:CreateEvent()A.InputChanged=q:CreateEvent()A.InputEnded=q:CreateEvent()end function a.OnInputBegan(O,g,I)if I then return end local Y=O.LastInputBeganTimes[g]or 0 local z=tick()if z-Y>=A then O.InputBegan:Fire(g)end O.LastInputBeganTimes[g]=z end function a.OnInputChanged(O,g,I)if I then return end local Y=O.LastInputChangedTimes[g]or 0 local z=tick()if z-Y>=A then O.InputChanged:Fire(g)end O.LastInputChangedTimes[g]=z end function a.OnInputEnded(O,g,I)if I then return end local Y=O.LastInputEndedTimes[g]or 0 local z=tick()if z-Y>=A then O.InputEnded:Fire(g)end O.LastInputEndedTimes[g]=z end function a.AddContext(A,g)local I={}table.insert(I,g:ConnectToHighestParent("\073\110\112\117\116\066\101\103\097\110",function(g,I)A:OnInputBegan(g,I)end))table.insert(I,g:ConnectToHighestParent("\073\110\112\117\116\067\104\097\110\103\101\100",function(g,I)A:OnInputChanged(g,I)end))table.insert(I,g:ConnectToHighestParent("\073\110\112\117\116\069\110\100\101\100",function(g,I)A:OnInputEnded(g,I)end))A.__ContextEvents[g]=I end function a.RemoveContext(A,g)local I=A.__ContextEvents[g]if I then A.__ContextEvents[g]=nil for g,A in pairs(I)do A:Disconnect()end end end O.DescendantAdded:Connect(function(g)if g:IsA("\071\117\105\079\098\106\101\099\116")then g.InputBegan:Connect(function(g,A)a:OnInputBegan(g,A)end)g.InputChanged:Connect(function(g,A)a:OnInputChanged(g,A)end)g.InputEnded:Connect(function(g,A)a:OnInputEnded(g,A)end)end end)I.InputBegan:Connect(function(g,A)a:OnInputBegan(g,A)end)I.InputChanged:Connect(function(g,A)a:OnInputChanged(g,A)end)I.InputEnded:Connect(function(g,A)a:OnInputEnded(g,A)end)return a
--[[
TheNexusAvenger

Static class for user input. Recommended to only use it
for key presses since the key presses are from all PluginGuis
and main viewport.
--]]

local CLASS_NAME = "NexusUserInput"

local INPUT_DELAY_TIME = 0.05



local UserInputService = game:GetService("UserInputService")
local PluginGuiService = game:GetService("PluginGuiService")

local NexusPluginFramework = require(script.Parent.Parent:WaitForChild("NexusPluginFrameworkProject")):GetContext(script)
local NexusContainer = NexusPluginFramework:GetResource("Base.NexusContainer")
local NexusEventCreator = NexusPluginFramework:GetResource("NexusInstance.Event.NexusEventCreator")

local NexusUserInput = NexusContainer:Extend()
NexusUserInput:SetClassName(CLASS_NAME)
NexusPluginFramework:SetContextResource(NexusUserInput)



--Create the events.
NexusUserInput.LastInputBeganTimes = {}
NexusUserInput.LastInputChangedTimes = {}
NexusUserInput.LastInputEndedTimes = {}
NexusUserInput.InputBegan = NexusEventCreator:CreateEvent()
NexusUserInput.InputChanged = NexusEventCreator:CreateEvent()
NexusUserInput.InputEnded = NexusEventCreator:CreateEvent()



--[[
Creates a User Input object.
--]]
function NexusUserInput:__new()
	self:InitializeSuper()
	self.Name = CLASS_NAME
	
	--Set up the context events.
	self.__ContextEvents = {}
	
	--Create the time checkers.
	self.LastInputBeganTimes = {}
	self.LastInputChangedTimes = {}
	self.LastInputEndedTimes = {}

	--Create the events.
	self.InputBegan = NexusEventCreator:CreateEvent()
	self.InputChanged = NexusEventCreator:CreateEvent()
	self.InputEnded = NexusEventCreator:CreateEvent()
end

--[[
Invoked when an input is began.
--]]
function NexusUserInput:OnInputBegan(InputObject,Processed)
	--Return if it was processed.
	if Processed then return end
	
	--Fire the event if it new.
	local LastTime = self.LastInputBeganTimes[InputObject] or 0
	local CurrentTime = tick()
	if CurrentTime - LastTime >= INPUT_DELAY_TIME then
		self.InputBegan:Fire(InputObject)
	end
	
	--Store the last time.
	self.LastInputBeganTimes[InputObject] = CurrentTime
end

--[[
Invoked when an input is changed.
--]]
function NexusUserInput:OnInputChanged(InputObject,Processed)
	--Return if it was processed.
	if Processed then return end
	
	--Fire the event if it new.
	local LastTime = self.LastInputChangedTimes[InputObject] or 0
	local CurrentTime = tick()
	if CurrentTime - LastTime >= INPUT_DELAY_TIME then
		self.InputChanged:Fire(InputObject)
	end
	
	--Store the last time.
	self.LastInputChangedTimes[InputObject] = CurrentTime
end

--[[
Invoked when an input is ended.
--]]
function NexusUserInput:OnInputEnded(InputObject,Processed)
	--Return if it was processed.
	if Processed then return end
	
	--Fire the event if it new.
	local LastTime = self.LastInputEndedTimes[InputObject] or 0
	local CurrentTime = tick()
	if CurrentTime - LastTime >= INPUT_DELAY_TIME then
		self.InputEnded:Fire(InputObject)
	end
	
	--Store the last time.
	self.LastInputEndedTimes[InputObject] = CurrentTime
end

--[[
Adds a context for getting inputs.
--]]
function NexusUserInput:AddContext(Frame)
	--Connect the events.
	local Events = {}
	table.insert(Events,Frame:ConnectToHighestParent("InputBegan",function(InputObject,Processed)
		self:OnInputBegan(InputObject,Processed)
	end))
	table.insert(Events,Frame:ConnectToHighestParent("InputChanged",function(InputObject,Processed)
		self:OnInputChanged(InputObject,Processed)
	end))
	table.insert(Events,Frame:ConnectToHighestParent("InputEnded",function(InputObject,Processed)
		self:OnInputEnded(InputObject,Processed)
	end))
	
	--Store the events.
	self.__ContextEvents[Frame] = Events
end

--[[
Removes a context for getting inputs.
--]]
function NexusUserInput:RemoveContext(Frame)
	--Disconnect the events.
	local Events = self.__ContextEvents[Frame]
	if Events then
		self.__ContextEvents[Frame] = nil
		for _,Event in pairs(Events) do
			Event:Disconnect()
		end
	end
end



--Connect the PluginGuis input events.
PluginGuiService.DescendantAdded:Connect(function(Frame)
	if Frame:IsA("GuiObject") then
		Frame.InputBegan:Connect(function(InputObject,Processed)
			NexusUserInput:OnInputBegan(InputObject,Processed)
		end)
		Frame.InputChanged:Connect(function(InputObject,Processed)
			NexusUserInput:OnInputChanged(InputObject,Processed)
		end)
		Frame.InputEnded:Connect(function(InputObject,Processed)
			NexusUserInput:OnInputEnded(InputObject,Processed)
		end)
	end
end)

--Connect the UserInputService.
UserInputService.InputBegan:Connect(function(InputObject,Processed)
	NexusUserInput:OnInputBegan(InputObject,Processed)
end)
UserInputService.InputChanged:Connect(function(InputObject,Processed)
	NexusUserInput:OnInputChanged(InputObject,Processed)
end)
UserInputService.InputEnded:Connect(function(InputObject,Processed)
	NexusUserInput:OnInputEnded(InputObject,Processed)
end)



return NexusUserInput