title: JavaFX : Keep listening to keyboard-input and on input perform action
body: <p>I have JavaFX project in which I have to listen to keyboard-input as our barcode scanner is configured that way.</p>
  
  <p>Are there any libraries in JavaFX where I can keep a listener active and perform suitable action upon reception of a String by barcode-scanner. </p>
  
  <p>I searched on net, but didn't find any good solution unfortunately. </p>
  
  <p>Here is my code :</p>
  
  <pre><code>    public class Main extends Application {
  
          private Scene scene;
          MyBrowser myBrowser;
  
          @Override
          public void start(Stage primaryStage) throws Exception{
              primaryStage.setTitle("Our Application");
              java.net.CookieManager manager = new java.net.CookieManager();
              java.net.CookieHandler.setDefault(manager);
  
              myBrowser = new MyBrowser();
              scene = new Scene(myBrowser, 1080, 1920);
  
              primaryStage.setScene(scene);
              primaryStage.setFullScreen(true);
              primaryStage.show();
  
  
          // @ being the escape character
          scene.setOnKeyTyped(new EventHandler&lt;KeyEvent&gt;() {
              @Override
              public void handle(KeyEvent event) {
                  String text = event.getCharacter();
                  if (text.equals("@")) {
                      String tempText = completeText;
                      completeText = "";
                      processText(tempText);
                  }else {
                      completeText = completeText+text;
                  }
              }
          });
  
          }
  
  private void processText(String text){
          System.out.println("I will process "+text);
      }
          public static void main(String[] args) {
              launch(args);
          }
  
  
      public class MyBrowser extends Region {
  
          final String hellohtml = "index.html";
  
          WebView webView = new WebView();
          WebEngine webEngine = webView.getEngine();
  
      public MyBrowser() {
              webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -&gt; {
                  if (newValue == Worker.State.SUCCEEDED) {
                      JSObject window = (JSObject) webEngine.executeScript("window");
                      window.setMember("app", this);
                  }
              });
  
              URL urlHello = getClass().getResource(hellohtml);
  
              webEngine.load(urlHello.toExternalForm());
              webView.setPrefSize(1080, 1920);
              webView.setContextMenuEnabled(false);
  
              getChildren().add(webView);
          }
  </code></pre>
  
  <p>Kindly let me know. Thank you. </p>