<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with setalwaysontop() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=setalwaysontop%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:25:03 +0000</pubDate>
         <description>Tagged with setalwaysontop() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedsetalwaysontop%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Create a new window/PApplet from another PApplet</title>
      <link>https://forum.processing.org/two/discussion/19677/create-a-new-window-papplet-from-another-papplet</link>
      <pubDate>Mon, 12 Dec 2016 01:02:56 +0000</pubDate>
      <dc:creator>colouredmirrorball</dc:creator>
      <guid isPermaLink="false">19677@/two/discussions</guid>
      <description><![CDATA[<p>I stumbled upon a way to easily spawn new windows from Processing and couldn't find it anywhere else so I thought I'd post it here. Unsure if it's the best way but it appears to be working. Feedback and improvements appreciated. This will only work for Processing 3.</p>

<p>First tab, for the demo to work right out of the box this sketch <strong>has</strong> to be called "SecondWindowTest"</p>

<pre><code>/**
 * Demo on how to spawn a second sketch from Processing
 * Facilitated by ControlP5, but not necessary for this purpose
 * by CMB, 2016
 *
 */



import controlP5.*;

ControlP5 cp5;

//Reference to the secondary sketch so we can call its methods and access its variables from outside
SecondSketch second;

//This value will be accessed by the other sketch
int backgroundValue = 0;

public void settings()
{
  size(800, 600);
}

public void setup()
{
  surface.setResizable(true);

  cp5 = new ControlP5(this);

  cp5.addButton("secondWindow")
    .setPosition(20, 20)
    .setSize(125, 25)
    .setLabel("Second Window")
    .getCaptionLabel().alignY(CENTER).alignX(CENTER);

  cp5.addTextfield("textField")
    .setSize(125, 25)
    .setPosition(20, 75);
}

public void draw()
{
  background(backgroundValue);
}

public void secondWindow()
{
  //Launch the other sketch!

  //This structure assumes you only want one instance of the other sketch
  //If that's not what you want simply call the constructor to launch a new, independent instance

  //if the other sketch is closed, start a new one
  if (second== null) second = new SecondSketch(this);
  else
  {
    //if it's already running, bring it to the front
    second.moveToTop();
  }
}

public void textField(String input)
{
  //Send some text to the other sketch
  if (second != null)
  {
    second.someText = input;
  }
}
</code></pre>

<p>Second tab</p>

<pre><code>//Code in this class like in any other sketch
//However, this class can't have any nested classes like a regular sketch:
//if you want to use another class inside this secondary sketch and draw in it,
//you gotta pass it a reference to this class and draw on its internal PGraphics "g"
class SecondSketch extends PApplet
{
  //A reference to the main sketch
  //notice how the file name of the main sketch is important as that becomes the name of the class upon compiling
  SecondWindowTest parent;

  ControlP5 gui;

  //This String will be sent to us from the main sketch
  String someText= "";

  //The constructor will take care of everything
  public SecondSketch(SecondWindowTest parent)
  {
    //store a reference to the first sketch so we can do things with it
    this.parent = parent;

    //This will actually launch the new sketch
    runSketch(new String[] {
      "SecondSketch"  //must match the name of this class
      }
      , this);  //the second argument makes sure this sketch is created instead of a brand new one...
  }

  public void settings()
  {
    size(700, 500);
  }

  public void setup()
  {

    super.surface.setResizable(true);

    //give it some GUI to interact with
    gui = new ControlP5(this);
    gui.addSlider("mainBackground")
      .setRange(0, 255)
      .setPosition(20, 50)
      .setLabel("Main sketch background colour")
      .setSize(125, 25);
  }

  public void draw()
  {
    background(50);
    fill(255);

    //Display the text that can be altered from the main sketch
    text(someText, 20, 20);
  }

  //Without this, the main sketch would close if the user clicked on the second sketch' close button!
  //(it appears to work funky with the escape button though, beware)
  public void exit()
  {
    parent.second = null;
    dispose();
  }

  //Callback from ControlP5
  public void mainBackground(float value)
  {
    //Change main sketch' background value
    parent.backgroundValue = (int) value;
  }

  //Little hack to bring the frame to the top
  public void moveToTop()
  {
    surface.setAlwaysOnTop(true);
    surface.setAlwaysOnTop(false);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>keeping sketch window in focus and actively listening</title>
      <link>https://forum.processing.org/two/discussion/9969/keeping-sketch-window-in-focus-and-actively-listening</link>
      <pubDate>Sat, 21 Mar 2015 22:23:22 +0000</pubDate>
      <dc:creator>ATPhillips</dc:creator>
      <guid isPermaLink="false">9969@/two/discussions</guid>
      <description><![CDATA[<p>I am working with a processing sketch that captures sends leap motion data via OSC.  In order for it to function correctly the sketch window needs to remain in focus.  I have used the frame.setAlwaysOnTop(true), and although the sketch window remains in the foreground, I cannot keep it actively listening when toggling between other applications.  Is it possible to keep the window it <em>always</em> listening?  Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Keyboard events and non-selected windows</title>
      <link>https://forum.processing.org/two/discussion/5316/keyboard-events-and-non-selected-windows</link>
      <pubDate>Thu, 22 May 2014 01:43:10 +0000</pubDate>
      <dc:creator>reepca</dc:creator>
      <guid isPermaLink="false">5316@/two/discussions</guid>
      <description><![CDATA[<p>Hello, so I was making a bit of an experimental project involving timed clicks (kind of like a macro, but with precise timing and the like) using Java's Robot class, and it worked as intended except for one problem - the way I toggled the timed clicking on and off was by changing a variable in keyPressed() depending on what 'Key' was when keyPressed() was called. Although the Robot was plenty willing to click outside of the display window, the program would stop registering the keys being pressed as soon as the display window was no longer selected - a considerable problem given that the reason I made the sketch was basically to push buttons <em>outside</em> of the sketch window. Is there a way to cause my program to listen to <em>all</em> keyboard events, not just the ones directed at it? So that I can have another window selected and still have it be capable of responding to keyboard input (for example, screen-recording software can be stopped by pressing a hotkey, but you can still have another window selected and hearing your key presses).</p>

<p>Any suggestions?</p>

<p>This doesn't really deal with core or contributed libraries, it's not really a hardware thing, and this seems like the most general place to put it, but apologies if there is a better place this should be.</p>
]]></description>
   </item>
   </channel>
</rss>