How do I setup a KeyListener that listens to the Windows key in JavaFX without the OS using that keypress as an action? Here is my code so far, but my OS just recognizes the keypress as an input and the program does not recognize it because of that:

package org.example;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class App extends Application {

    public static void main(String[] args) {
        launch();
    }

    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("app.fxml"));

        Scene scene = new Scene(fxmlLoader.load());
        scene.setOnKeyPressed(keyEvent -> System.out.println(keyEvent.getCode()));

        stage.setTitle("App");
        stage.setScene(scene);
        stage.show();
    }
}
0

There are 0 best solutions below