cseguin wrote:
I've been reading all docs about lookup api, nodeAction, GlobalContext....
You could listen on the main window's active/inactive state, although this won't tell you if the user walked away from the computer and left your app's main window active.
For something *that* general, you probably don't need anything special from NetBeans - just use an AWTEventListener and a timer - listen to all input events in all windows of the app globally. If too much time goes by between events, the app is idle. Something like this:
class IdleChecker implements AWTEventListener, ActionListener {
private static final int TIMEOUT = 120000; //2 minutes
private final Timer timer = new Timer(TIMEOUT, this);
private IdleChecker() {
timer.setRepeats(false);
timer.start();
}
static void init() {
IdleChecker main = new IdleChecker();
//Detect all focus events in the system. Ignore mouse events
//because mouseEntered() can happen w/o the window being active
Toolkit.getDefaultToolkit().addAWTEventListener(main,
AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
}
public void eventDispatched(AWTEvent event) {
//Force the timer to start counting from 0 again
timer.restart();
}
public void actionPerformed(ActionEvent e) {
//System has been idle > TIMEOUT milliseconds - do whatever here
}
}
-Tim