Parents feared a Dunblane or American school massacre when they saw a man with a gun walking near a Highland primary school.
The police were called and armed officers were dispatched to the scene near Inverlochy Primary School where the headmaster instructed an immediate lockdown to protect the children.
After a tense half hour, Malcolm Hilson was arrested and disarmed just after lunchtime on March 16, with police discovering his rifle was in fact a toy.
But Inverness Sheriff Court heard yesterday that Hilson, of no fixed abode, also had three knives hanging from his belt and rucksack.
The 32-year-old appeared from custody before Sheriff Eilidh Macdonald and had sentence deferred until July 24 for a background and psychiatric report.
Hilson admitted theft by housebreaking, possession of a firearm or imitation firearm with intent to cause fear of unlawful violence, and possession of knives.
Fiscal depute Roderick Urquhart told the court that Hilson was seen by a woman walking towards Inverlochy in the direction of a play park, carrying what appeared to be an assault rifle.
Mr Urquhart said: “The witness told police “he was just walking calmly carrying the gun like a soldier would.”
A few minutes later, concerned parents phoned the primary school about the man with the rifle.
Mr Urquhart added: “All pupils were locked inside the building, entrances and exits were secured , windows were blacked out and lights put out.
“Teachers were worried and pupils were upset, understandably so given events both in America and, previously, in Dunblane.
“The threat to safety of those inside the school appeared genuine.”
Mr Urquhart said police “boxed in” Hilson and when he walked towards four nursery children and their parents, an officer quickly moved into their path.
The court was told that Hilson was seen to have his finger on the trigger and when the officer told him to put the gun down, Hilson said: “it’s a toy.”
He was then taken into custody.
The day before the gun drama, Hilson had broken into a mountain sports shop in Fort William and stole £522 worth of clothing and equipment.