title: How can I detect the SPACE KeyEvent anywhere in my JavaFX app?
body: <p>I want to detect a <code>KeyEvent</code> regardless of what element has focus in my JavaFX app - in particular, I want to detect the <code>SPACE</code> key. I tried to add a listener to the <code>Scene</code> that corresponds to my window:</p>
  
  <pre><code>scene.setOnKeyPressed(ev -&gt; {
      if (ev.getCode() == KeyCode.SPACE) {
          System.out.println("GOOD");
      }
  });
  </code></pre>
  
  <p>But if I have a particular node with focus (like a <code>ListView</code> or <code>Button</code>) then it won't be detected.</p>
  
  <p>How can I detect when the <code>SPACE</code> key is pressed regardless of whatever the user is doing in my app? I don't intend to <em>interrupt</em> whatever node is receiving the <code>KeyEvent</code> - I just want to <em>know</em> if it happens. One (ugly) solution would be adding the listener to all my nodes, but I would rather not if possible.</p>