Virtual Keyboard

I am trying to create a virtual keyboard for a tuchscreen monitor and i cant figure out how to make it type a key when i touch a button. I am using it in a panel so that it can me activated from different windows. i need it to be able to type on the window that it opened from while the panel is open also. If anybody could help i would be very greatful.