AIR app – user idle detection

Found out that it is super easy to deal with timeouts…i.e. when you create kiosk applications, you generally want the activity to timeout and go to some sort of attract screen or activity reset when no one has touched the screen, move the mouse or press the keyboard.

There’s the NativeApplication class for AIR to the rescue:


/* this is in seconds */
NativeApplication.nativeApplication.idleThreshold = 60;
NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, handleUserIdle);
NativeApplication.nativeApplication.addEventListener(Event.USER_PRESENT, handleUserPresent);

private function handleUserIdle (e:Event) : void
{
  trace("Idling...");
  //reset activity
  //show attract screen
}

private function handleUserPresent (e:Event) : void
{
  trace("There's a user!");
  //hide attract screen
}

Leave a Reply