A Michigan man charged with killing six strangers between picking up rides for Uber pleaded guilty to murder on Monday, just before attorneys were set to interview jurors for his trial.

Jason Dalton's surprise move came nearly three years after the shootings, which occurred over the course of a few hours in and around Kalamazoo. Dalton pleaded guilty to murder and attempted murder over his attorney's objections, triggering a mandatory sentence of life in prison with no chance for parole.

"Yes, I've wanted this for quite a while," Dalton replied when a judge asked if the pleas were voluntary.

The 48-year-old also answered "yes" to a series of questions, admitting that he shot eight people at three locations. After his arrest, police quoted Dalton as saying a "devil figure" on Uber's app was controlling him on the day of the shootings.

Four women were killed in the parking lot of a Cracker Barrel restaurant on Feb. 20, 2016: Barbara Hawthorne, Dorothy (Judy) Brown, Mary Lou Nye, and her sister-in-law, Mary Jo Nye. Rich Smith and his 17-year-old son, Tyler, were fatally shot while looking at a pickup truck in a dealer's lot.

Abigail Kopf, who was 14 at the time, was shot in the head during the restaurant shooting and survived.

Tiana Carruthers, who was in a residential area, was seriously injured after being shot several times.

Dalton had been deemed competent to stand trial and last week dropped an insanity defence.

No explanation provided

In court, he didn't explain why he randomly shot eight people. Dalton, the father of two children, had worked as an insurance adjuster and had no previous criminal record before the shootings.

Prosecutor Jeff Getting said the motive behind the shootings is a question that "haunts us."

"Everybody wants to know," he said during a news conference after the court hearing.

Defence attorney Eusebio Solis said he advised Dalton not to plead guilty. But he said his client wanted to spare families more grief during a trial.

"I've been practising law for 30 years and have never pleaded to life in prison without parole," Solis said outside court.

Police are shown investigating the scene outside a Cracker Barrel restaurant in Kalamazoo, Mich., in this file photo. Eight people were shot at three locations on Feb. 20, 2016, leaving six dead. (Mark Bugnaski/Kalamazoo Gazette via Associated Press)

A gun shop owner said Dalton bought a jacket with an inside pocket designed to hold a gun just hours before the rampage. Shop owner Jon Southwick recalled Dalton "laughing and joking," and giving a "one-armed hug" to the manager before making the purchase.

Following the guilty pleas, Getting praised investigators and others who helped during the case, especially Alexis Cornish.

She was dating Tyler Smith and was in a vehicle when he and his father were shot while looking at trucks. Cornish was "extraordinarily brave" to immediately get a phone from her boyfriend's pocket and call 911, the prosecutor said.

Dalton's relatives and his former wife released a statement, expressing condolences to Kopf, Carruthers and the deceased victims' families for "this senseless tragedy."

"Nothing that we can say is adequate, but please know that our hearts are broken by the suffering which has resulted from the actions of our son and former husband," the statement said.