How to detect inactivity/idle time since last keypressed on j2me

余生颓废 提交于 2019-12-11 14:53:35

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1132190/how-to-detect-inactivity-idle-time-since-last-keypressed-on-j2me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!