But what problem, exactly, do you have
What methods, exactly, have you tried
What response
What event handler
What “main code”
Have you understood the nature of Event-Driven programming?
See: Good paper on Event-Driven Programming (as mentioned earlier).
Again, you haven’t actually stated what problem you’re having - so it’s impossible to give a solution