Q:

Slideshow: stop execution if mouse moved

jQuery 3.2.1
This is a photo gallery.
In HTML there is an element with id="forward".
It may be clicked by hand.
I'd like to organize a slideshow: wait for a certain
period then click forward element by JavaScript.
The code below executes this task:
$( document ).ready(function() {
    let pause = 3000; // ms

    function change_frame(){
        let $forward_elem = $("#forward");
        try {
            $forward_elem[0].click();
        }
        catch(TypeError){
            alert("The end!");
        }
    }

    setTimeout(
      function(){
        change_frame();
      }, pause);

});

But I want to add some functionality. Namely: if the mouse is moved,
don't do anything by JavaScript. 
In this case the user will just press forward element themselves (by hand). And the next page will again start counting down. In other words: if one doesn't touch the mouse, slideshow id going on automatically.
Could you help me here?

A:

You can declare a global variable like
var autoPresent = true
and then have a function that sets it to false when the mouse moves:
$(document).mousemove(function( event ) {
  autoPresent = false;
});

and then add this verification to your change_frame function
    function change_frame(){
        if (!autoPresent)
            return;

        let $forward_elem = $("#forward");
        try {
            $forward_elem[0].click();
        }
        catch(TypeError){
            alert("The end!");
        }
    }

and set it back the autoPresent = true where do you want to.
BUT
if you don't want to "autoPresent" anymore, just remove the clear the timeout:

Add a global variable like var nextSlide
Set your timeout to this variable: nextSlide = setTimeout(function(){change_frame();}, pause);
Clear it when the mouse moves:
$(document).mousemove(function( event ) {
    clearTimeout(nextSlide)
});

