当我最小化我的舞台时,JavaFX 不会触发我的 KeyPressed 事件。最小化舞台时如何收听 KeyEvent?
这里我称之为我的舞台:
public void start(Stage primaryStage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Gui.fxml"));
Parent root = fxmlLoader.load();
primaryStage.setTitle("KillSwitch");
primaryStage.setScene(new Scene(root));
primaryStage.getScene().getRoot().requestFocus();
primaryStage.show();
}
这是事件处理程序:
public void handleKeyInput(javafx.scene.input.KeyEvent event) throws InterruptedException, SerialPortException, IOException {
if (event.getCode() == KeyCode.UP) {
handletriggerButton();
}
}