Run code when window sketch get the focus

edited May 2017 in How To...

I want to run some code when the sketch get the focus...
Do you known some trick ?

Tagged:

Answers

  • edited May 2017 Answer ✓

    This works for me:

    boolean loseFocus;
    void setup()
    {
      size(300,300);
      background(0);
      loseFocus = false;
    }  
    
    void draw()
    {
      if (focused && loseFocus) 
      {
        println ("get focus");
        loseFocus = false;
      } 
      else if (!focused)
      {
        loseFocus = true;
      }
    }
    

    cameyo

  • edited May 2017

    @cameyo -- Interesting. That works for me as well on OS X 10.12.3 Processing 3.3.

    I didn't know about focused -- where did you learn about it?

  • edited May 2017

    @jeremydouglass:
    my editor highlights the word focused...
    then I have found it within the file \processing-3\modes\java\keywords.txt :)

    cameyo

Sign In or Register to comment.