Eighteen-year-old gunman Salvador Ramos remained inside the Uvalde school for an extended time before being fatally shot on Tuesday, according to a Texas Department of Public Safety (DPS) officer.

The Dallas Express previously reported that Ramos was allegedly responsible for shooting and killing 19 children and two teachers at the Robb Elementary School in Uvalde, Texas, on Tuesday.

At least 17 other people were injured and taken to nearby hospitals for treatment.

The time between when Ramos fired at the school security officer outside of the building and when the gunman was shot was 40 minutes to an hour, according to Texas DPS Director Steve McCraw.

According to witnesses, onlookers begged police officers to invade the school sooner.

CLICK HERE TO GET THE DALLAS EXPRESS APP

Juan Carranza, 24, was standing outside a house across the street and recalls hearing women shout at the officers, “Go in there! Go in there!”

“The bottom line is law enforcement was there,” said McCraw. “They did engage immediately. They did contain (Ramos) in the classroom.”

However, a department spokesman said Thursday that authorities were still trying to determine whether the 40-minute-to-an-hour period began when the gunman arrived at the school or earlier when he shot his grandmother at home.

“Right now, we do not have an accurate or confident timeline to provide to say the gunman was in the school for this period,” said Lt. Christopher Olivarez.

Facebook texts also revealed that Ramos was in contact with a 15-year-old girl who lives in Germany, and he messaged her before allegedly shooting his grandmother and heading to the school.

The messages reportedly disclosed that Ramos complained to the girl about his grandmother and said he was annoyed with her.

“I just shot my grandma in her head,” Ramos allegedly texted six minutes later.

Moments after, he said, “Ima go shoot up a[n] elementary school rn (right now).”

According to a spokeswoman for Meta, Facebook’s parent company, the gunman’s conversations were sent in a private direct messaging feature of Facebook and discovered after the shooting.

The girl said she spoke with Ramos on FaceTime and other social platforms daily and that “he looked happy and comfortable” when he talked to her.

Officials said the gunman was a local high school dropout with no criminal record and no known mental health issues. For his 18th birthday, he purchased two Armalite rifles, magazines, and ammunition.