Suhaib Mohammed, 19, was wounded at a house in Milton Keynes but died later in hospital.
Mohamed Noor, 33, of Radworthy, and Albert Prempeh, 35, of Langland Road, deny murder.
A jury at Luton Crown Court heard Mr Noor fired the revolver while Mr Prempeh acted as a lookout.
Prosecutor Justin Rouse told the court the victim was attacked at a house in Osprey Close, Eagleston, on 13 September.
He said Mr Noor entered the garden of the house and approached an open ground floor window.
"He was holding a revolver and reached through the window. He pulled the trigger two or three times. The gun clicked, but it did not discharge.
"He continued pulling the trigger and the gun fired," he said.
Mr Rouse added the shooting was carried out as part of a "murderous plan" acted out either in revenge, or in an attempt to steal money believed to be in the property.
The court heard Mr Noor told police the deceased and another man had attempted to rob him three weeks earlier, injuring him in the process.
Mr Prempeh claimed he only went with Mr Noor to the house because he was scared after being hit by his co-defendant earlier in the night, jurors were told.
The trial continues.
A teenager was fatally shot through an open window as part of a "murderous plan" which could have been an act of revenge, a court has heard.