tags:

views:

289

answers:

1

I have an application with a lot of screen (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 ? Thx a lot !

+3  A: 

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.

izb