We have a Swing application, currently I need to add a feature that is to do some jobs when user doesn’t operate the application for some time (e.g. 5 minutes). I have no idea how to implement this (maybe should monitor all the action events invoked by user, if for 5 minutes no new action even is raised do the jobs, but don’t know how). Any suggestions will be grateful.
Share
Add a system-wide AWTEventListener in order to receive all AWTEvents that you are interested in.
For example, the following code will tell you whenever the mouse enters, exits or is clicked within your swing application. It will also tell you whenever the user types any key within your application. Based on this information, you can start a timer in order to keep track of user “idle” time.
Take a look a the javadocs for the full list of event masks you can listen to.