如何检测自j2me上次按键以来的闲置时间/空闲时间 [英] How to detect inactivity/idle time since last keypressed on j2me
问题描述
我有一个具有很多屏幕的应用程序(其后是MVC模式),我希望能够以一种时尚的方式接收x秒前(比如说120秒)按下的最后一个键的信息.有标准的方法吗?还是我必须启动一个计时器,每次按下键时,我都必须覆盖一个变量,并且在计时器中,我必须检查该时间与当前时间之间的时差?
I have an application with a lot of screens (followed by MVC pattern), and I want to be able to receive in a fashion way the information that last key was pressed x seconds ago (120 sec let's say). Is there standard way to do this or I have to start a timer and every time when I pressed a key I have to override a variable and in the timer I have to check the difference time between that time and current time?
推荐答案
是的,只需在按下某个键时记录系统计时器即可.
Yes, just record the system timer when a key is pressed.
long epoch = System.currentTimeMillis();
再次按下某个键时,您需要检查时差以查看其空闲时间.
When a key is pressed again, you need to check the time difference to see how long it's been idle for.
如果您需要在没有按键的情况下触发事件,则需要启动一个线程,该线程会不时地唤醒以检查经过的时间,并在经过一段时间后触发某种事件.
If you need to trigger things without keypresses, then you need to start a thread which wakes now and again to check the elapsed time, and trigger an event of some kind when the time period has elapsed.
这篇关于如何检测自j2me上次按键以来的闲置时间/空闲时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!