How to detect if mouse has stopped moving?

edited July 2015 in How To...

Hi, is there a piece of code for this? I've been trying to search the interwebz but found nothing.

Answers

  • not really...

    you have to make it yourself

    e.g.

    void mouseMoved() {
        // gets called automatically
        lastTimeMouseMoved = millis(); 
    
    }
    

    before setup()

    int lastTimeMouseMoved  = -1; 
    

    then in draw() check how much time has past since the mouse moved the last time using

    howmuchtimehaspastsincethemousemoved = millis() - lastTimeMouseMoved  ; 
    
  • ok thanks

  • This is another way to do it. Processing remembers that previous mouse position. You can use this inside the draw () function.

    if (mouseX == pmouseX && mouseY == pmouseY){
      // mouse has not moved
    }
    
  • thanks...

    looks simpler...

    not sure if it'll work when we want to monitor a length of 0.5 secs though

  • Where did the 0.5 seconds come from? There is no mention of time in the question?

  • never mind

    just an example

    sry

    ;-)

  • No problem I just got confused, if you wanted to know how long the mouse was stationary you would need to use mills() :)

  • ah I see how you did it quark, ty.

  • mouseMoved() gets called automatically when the mouse moves

Sign In or Register to comment.