Hamlet rewrites portions of the play-within-a-play, wherein he wants to present a visual of poison being poured into a sleeping king's ear, hoping that this will rouse Claudius and cause a reaction that will be evidence of Claudius' murder of King Hamlet. "The play's the thing wherein I'll catch the conscience of the king," he says (II.ii.581-2). In the play-within, the murderer then courts the queen, who gradually succumbs to his advances. Hamlet writes into the play things that only Claudius would know, using the information provided to him by the ghost of his father.
His plan seems to work, because Claudius rises from his seat and cries for the lights (torches) to be lit. To Hamlet, Claudius' strong reaction to the scene is indicative of his guilt.
In Act 3, Scene 2 of Hamlet, Hamlet coaches the actors to produce a play that will make the king, Claudius, feel guilty by showing the way in which Hamlet's father was murdered. Hamlet tells Horatio about Claudius,
"If his occulted guilt Do not itself unkennel in one speech, It is a damnèd ghost that we have seen" (III.2.75-77).
In other words, they will observe Claudius during this scene and see if he seems guilty. If Claudius does not seem guilty, Hamlet will know that the ghost he saw was not real, but was just a spirit. During the play, the actors first perform in pantomime. They show a king and queen embracing. When the queen leaves, another man comes in and takes the king's crown and pours poison into the king's ear. When the queen returns to find the king dead, she is upset, but she eventually returns the other man's love. The players then act out this play, which Hamlet says is called The Mousetrap, using speech. The play reflects the situation in Denmark, where Claudius has murdered Hamlet's father, who was married to Gertrude, by pouring poison into his brother's ear. Claudius then becomes king and marries Gertrude.
After watching the play, Claudius gets up. He says, "Give me some light, away!" (III.2.254). He asks for the lights to be turned on, and he leaves, which Hamlet feels indicates that Claudius is guilty. Hamlet tells Horatio,
"O good Horatio, I’ll take the ghost’s word for a thousand pound. Didst perceive?" (III.2.260-262).
In other words, Hamlet believes the ghost was right and that Claudius murdered his father.