Believing the door was locked, he got his friend to give him a "boost" to peer in the window to see inside.
"He was up there for about three to five seconds then he jumped down and ran away," his friend said. "I said, 'what's wrong with you?' And he just had this terrified look on his face."
The boys, who usually hung out in a room for students with learning difficulties who "struggled to cope in the playground" at lunchtime, returned to their mates who noticed there was something wrong with their friend. When the boys pushed him, he told them what he'd seen.
The witness told the court in the few seconds he'd glanced through the window he'd been able to see the teacher sitting at the desk looking at a laptop. He hesitated and stammered, with prosector Nick Webby giving him lots of time.
"The, ah, he was, I was kind of ... his pants were down somewhat, he was masturbating."
Back in the lunchroom, the other boys had thought it was hilarious, the friend said. However, they soon noticed the witness was not laughing.
"He was trying to stay out of it. He never wanted to speak about it again. He didn't want the images going back into his mind," the boy said.
A teacher aide who overheard the boys laughing said he asked the student what was going on. "He just wanted me to drop it. He was shaking and nervous," the man said.
Defence lawyer Richard Earwaker did not believe the witness had seen the teacher masturbating. "Did you make a story up for your mates?" he asked. "No," the boy replied.
The defence disputes the allegation the act took place in public. The trial continues today.