Use the mouse_map out of panel, put it into your main function. Hopefully that solves your problem.
Edit: if you use the manual, don't stop at the first place. When you search for the mouse_map, you definitely got more than one hit. Please read all of them.