How can make my sketch know when the mouse is moved OUTSIDE of the sketch window?

edited June 2015 in Using Processing

The question says it all. If I'm not mistaken, I need to use something that consists of a Robot, or something like that?

Answers

  • edited June 2015 Answer ✓

    @TechWiz777, please choose "Ask a Question" rather than "New Discussion" for questions! :>

    Indeed w/ class Robot we can check mouse coordinates for the whole desktop:
    http://docs.Oracle.com/javase/8/docs/api/java/awt/Robot.html

    However we still need to find out which of those belong to the actual sketch's area! >-)
    Nonetheless I did a focused + thread("") sample. Check it out: B-)

    https://Processing.org/reference/focused.html
    https://Processing.org/reference/thread_.html

    // forum.processing.org/two/discussion/11471/
    // how-can-make-my-sketch-know-when-the-mouse-is-moved-
    // outside-of-the-sketch-window
    
    static final int POOLING_DELAY = 100;
    
    void setup() {
      size(400, 300, JAVA2D);
      noLoop();
      thread("focusThread");
    }
    
    void draw() {
      println(frameCount, focused);
    }
    
    void focusThread() {
      boolean previous = focused;
    
      for (;; delay(POOLING_DELAY))  if (previous != focused) {
        redraw = true;
        previous = focused;
      }
    }
    
Sign In or Register to comment.