— James Holmes was good at being invisible. He spoke only when spoken to, said little about himself, and spurned his close-knit group of classmates for a solitary life in his apartment.

This used to seem like Holmes’s curse, the result of a shyness that cut him off from the world.

This spring, however, it became a cover. When something apparently snapped in Holmes’s head — turning a pleasant, pun-loving 24-year-old into a man allegedly planning a mass murder — his lonely life meant there were few people close enough to see any change.

On Sunday, new details emerged about the way Holmes allegedly began assembling ammunition and explosives, attracting little attention from acquaintances. Signals of his apparently troubled mind — an odd online personal ad, a bizarre phone message heard by a gun-shop owner — leaked out, but to strangers.

Many of those closest to him didn’t know anything had changed — not until everybody else knew, too.

“I was always trying to get into his head,” said one fellow neuroscience student, who spent dozens of hours in class with Holmes at the University of Colorado campus in Aurora. “If no one had ever said anything to him, he wouldn’t have said a word” all year.

Police say Holmes, wearing a gas mask and SWAT-style protective gear, killed 12 people in a shooting rampage at an Aurora theater early Friday. Another 58 people were injured in the attack.

On Monday, Holmes will have an initial court hearing. A man who had always seemed desperate to avoid any attention will have propelled himself into an international spotlight.

Holmes, who grew up in the suburbs of San Diego, is recalled by his high school classmates as friendly — but largely unmemorable.

“My good grades are partially thanks to him,” said Brian Martinez, 24, who was Holmes’s lab partner in chemistry. They collaborated in class, but didn’t see each other much afterward: Holmes was not at parties, and he didn’t seem to have a large circle of friends, Martinez said.

After graduating from the University of California-Riverside, Holmes came to Aurora last fall to study neuroscience — learning how electrical signals transmit sensations and ideas in the brain. His first-year class was small: The school takes an average of six new students a year. That group spends hours each day together in a small conference room.

One fellow student said that Holmes was often the first to arrive at class, riding from his nearby apartment on a BMX bike more fit for an adolescent. But once class began, he had a habit of daydreaming.

“It’s like you’re interrupting” another train of thought that Holmes was pondering, the student said. The student asked not to be named because the school had urged Holmes’s classmates not to talk to the news media.

Holmes volunteered little information about his own life outside of the classroom. His fellow students could remember just one personal detail that Holmes revealed without prompting: During a conversation about football, he said he was a San Diego Chargers fan.

After classes, Holmes was always the first to leave. The other students, who bonded during this close experience, assumed he was just sequestered in his off-campus apartment.

“I always just figured he liked being alone,” the student said.

Four months ago, when Holmes allegedly began stockpiling ammunition and explosives, his behavior in class didn’t seem to change. Then came early June, when all first-year students faced a demanding oral exam. The exam came and went, and other students didn’t hear how Holmes did. Then they got word: He had sent an e-mail to administrators, saying he would leave school.

He didn’t give a reason, the school said.

Recently, Holmes appears to have sent some odd signals from his contracted world. On a dating site called Adult Friend Finder, someone who looks like Holmes posted a profile that said “Will you visit me in prison?”

And Holmes left a bizarre impression with Glenn Rotkovich, owner of a gun range called Lead Valley in Byers, Colo. Rotkovich said Sunday that he had received an e-mail from Holmes on June 25 asking for an application to join the shooting range.

He said he followed up with Holmes within a day or two, calling to inform him when to come to the range for orientation.

“I called him and I did not get him,” Rotkovich said. “I got his answering machine. It was a very bass, very deep-sounding, guttural voice that once you heard it, you realize it was not an accident. Somebody was trying to make it sound that way. It was an intentional act . . . bizarre or freakish. I could not make out certain words.”

Rotkovich called a couple more times in the following days and heard the same message.

“By the time I called the third time, my attitude is one that I don’t like this,” Rotkovich said. “So I told everybody, if James Holmes shows up, he’s doing nothing before I saw him. Is he weird? Is there something strange about this dude? I flagged it that he had to see me before he gets to do anything.”

Rotkovich said he forwarded the Holmes e-mail to authorities.

After the shooting at the theater Friday, police discovered a sophisticated set of explosive booby traps at Holmes’s run-down apartment near the university’s campus. Neighbors in his building and four other nearby buildings were awakened around 3 a.m. Friday by shouting police, telling them to evacuate.

What kind of a man would do this? Two residents of an apartment building across the street wondered Sunday about a man they had never seen. In the shade behind the Bonaparte apartments, Israel Trujillo and Freddy Martinez had just returned after days of evacuation.

While bomb squads slowly took apart the booby traps allegedly left by Holmes, the two men theorized in Spanish about their neighbor.

They decided that Holmes’ s goal was to get attention.

“He wanted to see himself on TV,” said Martinez, 32.

Research editor Alice Crites contributed to this report. Heath and Leonnig reported from Washington.