views:

574

answers:

3

How can I tell when a user has been idle for say 5 minutes on my Flex app?

When I say "idle" I mean the user has not interacted with the application at all.

Thanks!!

+1  A: 

Create a timer that you reset everytime you capture an user event at the application level.

If the timer has ended, then you know the user has been idle for that set amount of time.

// I am capturing only mouseMove and keyDown. That _should_ be enough to handle most user interactions.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" mouseMove="onUserEvent" keyDown="onUserEvent">

...

private function onUserEvent(event:Event):void
{
    timer.reset();
}
CookieOfFortune
Thanks, I have a question, if this is an AIR app, will it capture events from other windows as well? Thanks!
John Isaacks
Also, whenever the user is interacted with a modal popup over the application, the application doesn't seem to be receiving the events? is there a fix?
John Isaacks
+2  A: 

Being that this is an AIR app, I can just listen for the USER_IDLE event on the NativeApplication

//Set seconds for idle
this.nativeApplication.idleThreshold = 5; 
//listen for user idle
this.nativeApplication.addEventListener(Event.USER_IDLE,lock); 
John Isaacks
+1  A: 

See also the idle event in SystemManager. This approach works for AIR or Flash Player.

application.systemManager.addEventListener(FlexEvent.IDLE, onIdle);

You can get the idle time (in an unsupported way) using

SystemManager.mx_internal::idleCounter
Michael Brewer-Davis
Thanks for the info!
John Isaacks