title: Robot run in minimized application
body: <p>Forgive me if this question has been asked many times, but after looking up many of the questions I still can't find a definitive answer. I have a robot class that sends keyboard inputs like a macro running this in Eclipse. </p>
  
  <pre><code>import java.awt.AWTException;
  import java.awt.Robot;
  import java.awt.event.KeyEvent;
  
  
  public class Macro 
  {   
      public static void main (String args[]) throws AWTException, InterruptedException 
      {
           Robot r = new Robot();
           while(true) 
           {
                r.keyPress(KeyEvent.VK_V);
                r.keyRelease(KeyEvent.VK_V);
                r.delay(500);
                r.keyPress(KeyEvent.VK_T);
                r.KeyRelease(KeyEvent.VK_T);
                r.delay(500);
          }
      }
  }
  </code></pre>
  
  <p>Assume this scenario where run the robot, open notepad, put focus into notepad, the program will work fine typing the keys into notepad. However, If I were to minimize notepad, open up google, the robot will start typing in google and not notepad. <strong>What I want is that the robot will ONLY run in my selected program (for example notepad) AND ALSO RUN when that selected program is minimized.</strong> This way my robot can run in the minimized program, and I can do other things within my computer without the robot affecting me.</p>
  
  <p>I've heard scenarios where its not possible in java and that I have to this in native code, but others have said it is possible with extensions such as JNativeHook or some type of Actionlisteners. I delved into JNativeHook yet it doesn't seem to fix my exact problems. JNativeHook was able to give keyboard input detection while Ecipse was minimized, yet rather than Eclipse detecting my Keyboard inputs, I wanted a selected program of my choice (for example notepad) to detect the keyboard inputs.  </p>
  
  <p>The second problem was, I didn't want "GLOBAL" detection, but rather to filter the detection to ONLY my robot class. Therefore it will be able to distinguish detection from my typing and the robot typing. Even if I could solve the first two problems. The third problem would be that I wanted the robot to type ONLY within the selected application (for example notepad) and not interfere with whatever I'm typing while doing other things. </p>
  
  <p>Is what I want to achieve possible with Eclipse/java ? Is there an alternative ? Any input is greatly appreciated.</p>