By inactivity, I mean no mouse move, no key pressing...
I want to record the duration that users are being inactive. For example, a user is inactive for 1 minute, then re-active, then another 2 minutes of inactivity. I want to have a record like [1, 2].
Both javascript and jquery accepted.
Thanks for any help!
I have a hidden form in html. Thinking to store the record there.The following is what I tried (adopted from another topic). It records every 5 seconds, like 0, 5, 10... If the inactivity lasts for 11 seconds, I want only store 11 instead of 0, 5, 10, which also does not capture 11, but only 10.
var idleTime = 0;
var inactivity = '0'; //record seconds of inactivity
var inactivity_form = $("#id_inacticity");
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 1000);
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keydown(function (e) {
idleTime = 0;
});
setInterval(inactivity_record, 5000)
});
function timerIncrement() {
idleTime = idleTime + 1;
console.log('idletime',idleTime)
}
function inactivity_record() {
if (idleTime >= 5){
inactivity = inactivity + ';' + idleTime
inactivity_form.val(inactivity)
//console.log('inactivity', inactivity)
}
}