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

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

	if gameProcessed and self:IsVisible() == false 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
		wait()
		self:SetEntryText(self:GetEntryText():gsub("\n", ""):gsub("\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
