SUSSEX, New Brunswick — A small group of Sussex high school students got the writing critique of a lifetime Friday morning when literary horror-master Stephen King made a surprise visit to their school.

King, the renowned author of books such as “The Stand,” “The Shining,” “The Dark Tower” series, “The Green Mile” and the recent JFK book “11/22/63: A Novel,” gathered with 18 lucky students in the school’s library to provide feedback on their work.

“I thought it was absolutely insane that he was actually at our school,” said Matthew Beyer, a 12th-grade student who shook King’s hand.

“It was quite a shock. We just walked into the library and Stephen King is standing there.”

King then spoke to about 80 other students in the auditorium where he told them about his short time as a high school teacher and about how he dreams up the ideas for his novels.

King was at the school after a yearlong campaign to get the author, who lives in Bangor, Maine, to visit the school by Halloween 2012.

The idea was hatched in vice principal Phyllis Corbett’s car last October when Corbett, other teachers and librarian Patricia Stout were discussing potential literacy projects and ways to get students engaged.

That’s when they came up with “Seeking Stephen King.”

All 32 English classes were studying persuasive writing and over the course of the last year they used what they learned to send 1,100 letters to the famous recluse.

Media studies, theater arts, and music and arts classes also jumped on board the campaign, coming up with innovative ways to attract King. About a dozen videos were created, including a rap video, which King apparently watched and enjoyed, according to Corbett.

Dozens of posters were created, and a large caricature of King’s head was painted, a prop that will soon be shipped to King.

Sarah-Jane Smith, the teacher spearheading the effort to bring King to town said she didn’t know he was coming this week until she received a call from the literary icon on Thursday.

“He said, ‘I’m coming tomorrow.’ I was just shocked,” Smith said.

Beyer said he heard rumours in the morning about the visit, but he didn’t really believe them until he walked into the library a few hours later.

While Beyer said he has only read excerpts of King’s work so far, he’s going to change that.

“It was inspiring,” he said.

Although Beyer’s writing wasn’t among the work read by King, the author told the students they could mail their material to him and he’d read it and send back his feedback.

“It was a great experience, it makes you think of writing in a different way. To get a professional world-renowned writer to come in and just talk about how writing works, it adds just a whole new light on it,” he added.

“It makes big dreams like being a writer like him seem less far away.”

While King’s visit was meant to be kept as secretive as possible at the author’s request, word about his visit spread quickly after a student spotted King at an Irving gas station in town and then started texting others.

King had expressly forbid the school from notifying media and he did not want to be interviewed. He also asked to limit the size of the groups he would speak with to keep it manageable.

After King held his hourlong session in the library with the smaller group, he held a second 45-minute session in the school’s auditorium for about 80 students.

While only a small number of the student body was able to hear King speak in person, students were posting on Twitter and Facebook, spreading the news further.

Dressed casually in a gray T-shirt and jeans, King sat on the edge of the stage to talk about his writing and how he comes up with the macabre and sometimes twisted ideas that have made him one of the best-selling authors of all time.

He remarked about the small size of Sussex and said inspiration can be found all around, even in smaller towns.

Before reading a passage from his book “Christine,” he talked about his time as a teacher and bullying.

“One thing I decided after teaching high school for two years was that secretly, most kids feel like they’re out, that nobody likes them,” he told the students.

Nathan Brown and Jed Webster, the two 12th-grade students who made headlines last spring by creating the YouTube hit and video love letter to their hometown, “From Sussex and I Know It,” filmed King’s visit.

They said they’ll spend the weekend editing the footage and hope to have it online by Sunday night.

Brown said he felt starstruck but remarked at how down-to-earth the author acted.

“It was good to know he listens to us, that he was looking at the letters,” Webster said.

Corbett said during the short time she spent with King, she found him to be “just a kind, gentle guy.”

“He was just a funny, self-deprecating man,” she said.

King left the school at noon, refusing to sign autographs since it would take too long.

“I have to get back to Maine, there’s a storm coming so I want to be back by five,” he told the crowd at the auditorium.

King stopped in the office and signed 10 copies of “Different Seasons,” a collection of stories, and he also collected many of the posters students had created before he hit the road.

Corbett said the author also left with a brown-bag lunch the school’s administration packed for his drive home that included Pepsi, water, a wrap, popcorn and granola bars.

“We set the bag in his passenger seat. Sarah-Jane wished him a safe trip. ‘From you lips to God’s ears,’ he said to her. It was really sweet,” Corbett said.