Pavlovia - JS Stop Routine if Mouse Stops Moving

I want to stop the routine and display a specific feedback if participants’ mouse stops moving for a certain amount of time. I understand in JS there is a timeout function, but I am unsure how to incorporate this into the code. Currently, I have:

document.onmousemove = function(){
  timeout = setTimeout(function(){
    abort = 2;
    continueRoutine = false;
    fdbk_to_draw = "Please keep moving your mouse.";
    }, 10000);

But this does not give me what I want.

Hi There,

Here is a demo where we do a similar thing (should work locally and online). shows the number of frames the mouse has not moved for and ends a routine if a movement hasn’t been made in X frames.trackMouse2.psyexp (11.9 KB)

Hope this helps,

You could also look at this thread that discussed a similar problem: Abort Trial If Mouse Stops Moving