Check if there is no movement on screen or Click from keyboard

javascript, jquery

Solution

You can create a function that will send a "No activity event" after XX seconds and just reset this timer every time you get a mouse or keyboard event.

Here is an example with `.mousemove`:

var global = 10;

function noMovement() {
  if (global == 0) {
    alert('no movement');
    resetGlobal();
  } else {
    global--;
  }
}

function resetGlobal() {
  global = 10;
}

$(function() {
  $('html').mousemove(function(event) {
    resetGlobal();
  });
});

setInterval(function() {
  noMovement();
}, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Problem

i want to know if there is option to check if there is no movement on screen by click or mouse movements? for exmaple check if there is no 'activity' on the web. i look around the codes here in the site and found that. i dont know if it will help. ``` <pre> <script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $('html').mousemove(function(event){ console.log("mouse move X:"+event.pageX+" Y:"+event.pageY); }); $('html').click(function(event){ console.log("mouse click X:"+event.pageX+" Y:"+event.pageY); }); $('html').keyup(function(event){ console.log("keyboard event: key pressed "+event.keyCode); }); }); </script> </pre> ```

Original source