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