title: How to connect JNativeHook to JavaFX Thread?
body: <p>I'm making a translator program that has a gui in Javafx.  I am using JNativeHook to enable global keylisteners for when the app is not in focus.  When alt and t are pressed at the same time, the program is supposed to restore itself from the taskbar.  </p>
  
  <p>However, when i press alt and t, it get an error saying the JNativeHook thread cannot run with the javafx thread.</p>
  
  <p>Is it even possible to have the GlobalScreen thread communicate with the javafx thread?</p>
  
  <p>This is my Global keylistener code</p>
  
  <pre><code>GlobalScreen.addNativeKeyListener(listener);
  </code></pre>
  
  <p>and this is my listener</p>
  
  <pre><code>                @Override
                  public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) {
                      if(nativeKeyEvent.getKeyCode() == NativeKeyEvent.VC_ALT_L){
                          alt = true;
                      }
                      if(nativeKeyEvent.getKeyCode() == NativeKeyEvent.VC_T){
                          t = true;
                      }
  
                      check();
  
                  }
  
                  @Override
                  public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) {
                      if(nativeKeyEvent.getKeyCode() == NativeKeyEvent.VC_ALT_L){
                          alt = false;
                      }
                      if(nativeKeyEvent.getKeyCode() == NativeKeyEvent.VC_T){
                          t = false;
                      }
                  }
  
                  @Override
                  public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) {
  
                  }
              });
  </code></pre>
  
  <p>the error im getting is</p>
  
  <pre><code>Exception in thread "JNativeHook Dispatch Thread" java.lang.IllegalStateException: Not on FX application thread; currentThread = JNativeHook Dispatch Thread
  at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:204)
  </code></pre>
  
  <p>In case your aren't familiar with the GlobalScreen, it is basically adding a keylistener to your java program when it is not in focus and are using other things on your computer.</p>
  
  <p>Is there any way i can have the JNativeHook thread access my javafx thread to reopen the program with a hotkey after it has been minimized?</p>