You can check for key events by defining these listeners:
About the touch events, you can detect them by implementing one or more of these listeners:
For your specific needs, I think It would be enough to check for onkeypress and onmousedown events. Within these events, just check and store in a variable the current time. Then, by using that variable and a predefined time delta, you should be able to detect if your user is actively using the Widget, or not.