Hamlet wrote a love note to Ophelia in Scene 2 which seems to be sane. He tells her he loves her. She has been ignoring him on the advice of her father, Polonius, who does not think Hamlet really loves her so he tells her to stay away from him. So, he writes to her and assures her that he does love her. There is nothing in this note that sounds like a madman.
Hamlet later runs into Polonius while Hamlet is walking and reading. Hamlet recognizes Polonius because he asks him if he has a daughter, but when Polonius asks Hamlet if he knows who he is, Hamlet replies, “You are a fishmonger!” He is playing mind games with Polonius and Polonius even recognizes this because he says, “Though this is madness, yet there be method in it” meaning that if he didn’t know better, he would not think Hamlet so crazy because much of what he is saying makes sense (Hamlet is talking about old men). Polonius also replies, “How full of meaning his replies sometimes are.”
Next, Hamlet meets with his two old friends Rosencrantz and Guildenstern and his conversation does not show any sign of madness, just irony and sarcasm over the state of affairs in Denmark. Hamlet suspects that Claudius has put Rosencrantz and Guildenstern up to something – to find out information about him. He says:
You were sent for, and
there is a kind of confession in your looks, which you are
not very good at hiding. I know the good king and queen
have sent for you.
Finally, Hamlet arranges for the traveling group of actors to perform a play within a play to expose Claudius’ villainy. He is not acting mad throughout this entire part of the scene either and even asks the actors to perform additional lines which Hamlet will write:
We'll have it tomorrow night. You could, as necessary,
study a speech of some dozen or sixteen lines which I
would write down and insert into it? Couldn’t you?
You can read this Act yourself here on eNotes.