function Window.BeginInput(K,q,y)if GuiService.MenuIsOpen then K:Hide()end if y and not K:IsVisible()then return end if K.Cmdr.ActivationKeys[q.KeyCode]then if K.Cmdr.MashToEnable and not K.Cmdr.Enabled then if tick()-lastPressTime<1 then if pressCount>=5 then return K.Cmdr:SetEnabled(true)else pressCount=pressCount+1 end else pressCount=1 end lastPressTime=tick()elseif K.Cmdr.Enabled then K:SetVisible(not K:IsVisible())wait()K:SetEntryText("")if GuiService.MenuIsOpen then K:Hide()end end return end if K.Cmdr.Enabled==false or not K:IsVisible()then if K:IsVisible()then K:Hide()end return end if K.Cmdr.HideOnLostFocus and table.find(MOUSE_TOUCH_ENUM,q.UserInputType)then local y=q.Position local b=Gui.AbsolutePosition local d=Gui.AbsoluteSize if y.X<b.X or y.X>b.X+d.X or y.Y<b.Y or y.Y>b.Y+d.Y then K:Hide()end elseif q.KeyCode==Enum.KeyCode.Down then K:SelectVertical(1)elseif q.KeyCode==Enum.KeyCode.Up then K:SelectVertical(-1)elseif q.KeyCode==Enum.KeyCode.Return then task.wait()K:SetEntryText(string.gsub(string.gsub(K:GetEntryText(),"\n",""),"\r",""))elseif q.KeyCode==Enum.KeyCode.Tab then local q=K.AutoComplete:GetSelectedItem()local y=K:GetEntryText()if q and not((y:sub(#y,#y)):match("\037\115")and K.AutoComplete.LastItem)then local y=q[2]local b local d=true local c=K.AutoComplete.Command if c then local q=K.AutoComplete.Arg b=c.Alias d=K.AutoComplete.NumArgs~=#c.ArgumentDefinitions and K.AutoComplete.IsPartial==false local E=c.Arguments for K=1,#E,1 do local d=E[K]local c=d.RawSegments if d==q then c[#c]=y end local j=d.Prefix..table.concat(c,"\044")if j:find(" ")or j==""then j=("\037\113"):format(j)end b=("\037\115 \037\115"):format(b,j)if d==q then break end end else b=y end wait()K:SetEntryText(b..(d and" "or""))else wait()K:SetEntryText(K:GetEntryText())end else K:ClearHistoryState()end end

function Window:BeginInput(input, gameProcessed)
	if GuiService.MenuIsOpen then
		self:Hide()
	end

	if gameProcessed and not self:IsVisible() then
		return
	end

	if self.Cmdr.ActivationKeys[input.KeyCode] then -- Activate the command bar
		if self.Cmdr.MashToEnable and not self.Cmdr.Enabled then
			if tick() - lastPressTime < 1 then
				if pressCount >= 5 then
					return self.Cmdr:SetEnabled(true)
				else
					pressCount = pressCount + 1
				end
			else
				pressCount = 1
			end
			lastPressTime = tick()
		elseif self.Cmdr.Enabled then
			self:SetVisible(not self:IsVisible())
			wait()
			self:SetEntryText("")

			if GuiService.MenuIsOpen then -- Special case for menu getting stuck open (roblox bug)
				self:Hide()
			end
		end

		return
	end

	if self.Cmdr.Enabled == false or not self:IsVisible() then
		if self:IsVisible() then
			self:Hide()
		end

		return
	end

	if self.Cmdr.HideOnLostFocus and table.find(MOUSE_TOUCH_ENUM, input.UserInputType) then
		local ps = input.Position
		local ap = Gui.AbsolutePosition
		local as = Gui.AbsoluteSize
		if ps.X < ap.X or ps.X > ap.X + as.X or ps.Y < ap.Y or ps.Y > ap.Y + as.Y then
			self:Hide()
		end
	elseif input.KeyCode == Enum.KeyCode.Down then -- Auto Complete Down
		self:SelectVertical(1)
	elseif input.KeyCode == Enum.KeyCode.Up then -- Auto Complete Up
		self:SelectVertical(-1)
	elseif input.KeyCode == Enum.KeyCode.Return then -- Eat new lines
		task.wait()
		self:SetEntryText(string.gsub(string.gsub(self:GetEntryText(), '\n', ''), '\r', ''))
	elseif input.KeyCode == Enum.KeyCode.Tab then -- Auto complete
		local item = self.AutoComplete:GetSelectedItem()
		local text = self:GetEntryText()
		if item and not (text:sub(#text, #text):match("%s") and self.AutoComplete.LastItem) then
			local replace = item[2]
			local newText
			local insertSpace = true
			local command = self.AutoComplete.Command

			if command then
				local lastArg = self.AutoComplete.Arg

				newText = command.Alias
				insertSpace = self.AutoComplete.NumArgs ~= #command.ArgumentDefinitions
					and self.AutoComplete.IsPartial == false

				local args = command.Arguments
				for i = 1, #args do
					local arg = args[i]
					local segments = arg.RawSegments
					if arg == lastArg then
						segments[#segments] = replace
					end

					local argText = arg.Prefix .. table.concat(segments, ",")

					-- Put auto completion options in quotation marks if they have a space
					if argText:find(" ") or argText == "" then
						argText = ("%q"):format(argText)
					end

					newText = ("%s %s"):format(newText, argText)

					if arg == lastArg then
						break
					end
				end
			else
				newText = replace
			end
			-- need to wait a frame so we can eat the \t
			wait()
			-- Update the text box
			self:SetEntryText(newText .. (insertSpace and " " or ""))
		else
			-- Still need to eat the \t even if there is no auto-complete to show
			wait()
			self:SetEntryText(self:GetEntryText())
		end
	else
		self:ClearHistoryState()
	end
end
