-1

I'm currently working with JavaFX key listeners. I'm able to identify keyboard input but my algorithm requires detecting the inactivity on keyboard. Is there a keycode or any other object that identifies inactivity?

kleopatra
  • 51,061
  • 28
  • 99
  • 211

1 Answers1

-1

Well, after a little research I found the answer. We can detect the inactivity by recording the difference between the time of the last activity and the current time.

For example:

double activityTime;
if(event){
  activityTime = System.currentTimeMillis()*1000; // *1000 will convert milliseconds to seconds
}
if(System.currentTimeMillis()*1000 - activityTime > 5){
    //This block will be triggered after 5 seconds of inactivity
    //statements
}