Stop Win + R from launcher launcher

My javafx program has a popup that allows the user to press keys and then sets the label accordingly. My problem is with keyboard shortcuts that are shortcuts to the underlying OS, for example if the user presses Win + R and then runs Run.exe, but my program should just set the shortcut to "Win + R". My question is how to stop keyevents from launching OS shortcuts.

Here is the relevant code.

public void showInput() {
        Set codes = new HashSet();

        Stage inputWindow = new Stage();
        GridPane pane = new GridPane();
        Scene scene = new Scene(pane);
        Label label = new Label("Here comes the pressed keys");

        scene.setOnKeyPressed(e -> {
            e.consume();
            int code = e.getCode().ordinal();

            if (label.getText().equals("Here comes the pressed keys")){
                codes.add(code);
                label.setText(String.valueOf(e.getCode().getName()));

            } else if (!codes.contains(code)){
                codes.add(code);
                label.setText(label.getText() + "+" + e.getCode().getName());
            }
        });

        scene.setOnKeyReleased(e -> {
            e.consume();
            inputWindow.close();
        });

        pane.add(label, 0, 0);

        inputWindow.setScene(scene);
        inputWindow.show();
    }
      

I tried e.consume()

it but it didn't help.

+3


source to share





All Articles