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