An accused White House shooter, who allegedly called U.S. President Barack Obama the devil and anti-Christ, was ordered on Monday to undergo a mental exam to determine his competency to face charges of attempting to kill the president.

Obama and his wife, Michelle, were in California at the time of the alleged shooting the night of November 11, and no one was hurt. The Secret Service said one bullet broke a White House window but was stopped by protective ballistic glass, and another one struck the building's exterior.

At a hearing, federal magistrate judge Alan Kay granted a request by prosecutors for a mental screening for the defendant, Oscar Ortega-Hernandez, 21, of Idaho Falls, Idaho.

Kay said he wanted to make sure the defendant, who attended the brief hearing, understood the charges against him and could assist his lawyers in his defence. The brief screening will be done by a psychologist or other appropriate expert, he said.

The defendant, who was arrested on Wednesday at a hotel near Indiana, Pennsylvania, was moved to Washington after a court hearing last week in Pittsburgh.

Ortega-Hernandez only spoke once to the judge. No, I do not, he said when Kay asked if he any money to hire his own lawyers. Representing him now are assistant public defenders.

The judge ordered that Ortega-Hernandez, who faces up to life in prison if convicted of attempting to assassinate Obama, remain in jail and set the next hearing for November 28.

Kay said prosecutors made a sufficient showing that the case should go forward and he rejected a defence request to dismiss the charges because of a lack of evidence.

According to an FBI affidavit, an unidentified witness in Idaho who knows Ortega-Hernandez told authorities the defendant wanted to hurt Obama and referred to him as the anti-Christ.

Another witness in Idaho told authorities Ortega-Hernandez was very specific that Obama was the problem with the government and called him the devil, the affidavit said.

(Reporting by James Vicini; editing by Mohammad Zargham)