我如何知道当用户已闲置比如5分钟,我的Flex应用程序?

当我说“空闲”我的意思是用户没有与应用程序交互的。

谢谢!

其他提示

作为这是AIR应用程序,我可以监听了NativeApplication

的USER_IDLE事件
//Set seconds for idle
this.nativeApplication.idleThreshold = 5; 
//listen for user idle
this.nativeApplication.addEventListener(Event.USER_IDLE,lock); 

创建重置每次您捕获在应用程序级别的用户事件的定时器。

如果计时器已经结束,那么你就知道用户已空闲的时间设定金额。

// 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();
}

可以通过使用下面的代码得到超时:

 <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               minWidth="955" minHeight="600"
               initialize="init(event)">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.core.mx_internal;
            import mx.events.FlexEvent;

            protected function init(event:FlexEvent):void
            {
                systemManager.addEventListener(FlexEvent.IDLE, handleApplicationIdle);
            }

            private function handleApplicationIdle(event:FlexEvent):void
            {
                if(event.currentTarget.mx_internal::idleCounter == 60){
                    Alert.show("Time out happened");
                }
            }
        ]]>
    </fx:Script>
</s:Application>

@迈克尔布鲁尔-Davis公司

systemManager.addEventListener(FlexEvent.IDLE,ONIDLE)鼠标事件工作正常。

有关键盘事件是什么。你必须有一些重点元素systemManager的监听键盘事件之前。

<强>部分解决方案: 在applicationComplete事件中,我添加了下面一行    stage.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown); 现在,键盘事件得到倾听。

<强>缺点:只有应用被点击一次ATLEAST后的工作原理。然后工作后细

有没有什么办法让应用程序监听键盘事件没有一次点击的麻烦。有的建议在“stage.focus =这个”。没有任何工作。(静止点击需要)

scroll top