title: Java.awt.Robot keyPress and keyRelease not working at all
body: <p>Whenever I try using the java.awt.Robot keyPress or keyRelease, it gives me the error message <code>pid(25807)/euid(501) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!</code>. No matter how simple I make the code, it keeps giving this error message. This is my code:</p>
  <pre><code>package com;
  import java.awt.AWTException;
  import java.awt.Robot;
  import java.awt.event.InputEvent;
  import java.awt.event.KeyEvent;
  
  public class JavaRobotExample {
      public static void main(String[] args) throws AWTException {
          Robot robot = new Robot();
      
          robot.keyPress(KeyEvent.VK_A);
          robot.keyRelease(KeyEvent.VK_A);
      }
  }
  </code></pre>
  <p>This is the textbook example I found, yet it still gives that error message. I've been searching for so long trying to figure out what is wrong. I use MacOS Mojave 10.14.2 on a MacBook Pro, and I have given Eclipse (what I use to compile the code) privacy access. Here is a screenshot of everything I use for this:
  <a href="https://i.stack.imgur.com/yXz9d.png" rel="nofollow noreferrer">My code</a></p>
  <p>Does anyone else have this issue? I should also note that the error message is sent multiple times, even though it only presses the key once.</p>