Have you tried calling the function whenever? Sounds like a fairly easy thing to do. It says on the website that you need to call it onClick, but I doubt it is limited to clicks only.
The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.
How to ask smart questions?