Example usage for javafx.scene.input KeyEvent getCode

List of usage examples for javafx.scene.input KeyEvent getCode

Introduction

In this page you can find the example usage for javafx.scene.input KeyEvent getCode.

Prototype

public final KeyCode getCode() 

Source Link

Document

The key code associated with the key in this key pressed or key released event.

Usage

From source file:Main.java

private static int keyCode(final KeyEvent event) {
    if (null == event) {
        return 0;
    }//from ww w .  j a v  a2  s.c  o  m
    switch (event.getCode()) {
    case UP:
        return java.awt.event.KeyEvent.VK_UP;
    case DOWN:
        return java.awt.event.KeyEvent.VK_DOWN;
    case LEFT:
        return java.awt.event.KeyEvent.VK_LEFT;
    case RIGHT:
        return java.awt.event.KeyEvent.VK_RIGHT;

    case PAGE_UP:
        return java.awt.event.KeyEvent.VK_PAGE_UP;
    case PAGE_DOWN:
        return java.awt.event.KeyEvent.VK_PAGE_DOWN;

    case BACK_SPACE:
        return java.awt.event.KeyEvent.VK_BACK_SPACE;
    case DELETE:
        return java.awt.event.KeyEvent.VK_DELETE;

    case ESCAPE:
        return java.awt.event.KeyEvent.VK_ESCAPE;

    default:
        return 0;
    }
}

From source file:Main.java

/**
 * Handle action related to input (in this case specifically only responds to
 * keyboard event CTRL-A)./*from www.j a  v  a  2 s  . c  o  m*/
 * 
 * @param event Input event.
 */
@FXML
private void handleKeyInput(final InputEvent event) {
    if (event instanceof KeyEvent) {
        final KeyEvent keyEvent = (KeyEvent) event;
        if (keyEvent.isControlDown() && keyEvent.getCode() == KeyCode.A) {
            provideAboutFunctionality();
        }
    }
}

From source file:account.management.controller.SalaryVoucherController.java

/**
 * Initializes the controller class./*from   w w  w  . j a  v  a 2s  .  co  m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.amount_words.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit deposit voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        try {
                            onSubmitButtonClick(null);
                        } catch (ParseException ex) {
                            Logger.getLogger(SalaryVoucherController.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        }
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();
}

From source file:by.zuyeu.deyestracker.reader.ui.readpane.ReadPaneController.java

private void addScrollTracker() throws DEyesTrackerException {
    LOG.info("addScrollTracker() - start;");
    if (!scrollExist) {
        application.getStage().addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent evt) -> {
            if (evt.getCode().equals(KeyCode.DOWN)) {
                Platform.runLater(() -> {
                    LOG.debug("down - vvalue = {}", spText.getVvalue());
                    spText.setVvalue(spText.getVvalue() + spText.getVmax() / 10);
                });//from   ww w  .j av  a2s. c  o  m
            }
            if (evt.getCode().equals(KeyCode.UP)) {
                Platform.runLater(() -> {
                    LOG.debug("up - vvalue = {}", spText.getVvalue());
                    spText.setVvalue(spText.getVvalue() - spText.getVmax() / 10);
                });
            }
        });
        final Thread t = new Thread() {
            @Override
            public void run() {
                runEyeTracker();
            }
        };
        t.setDaemon(true);
        t.start();

        scrollExist = true;
    }
    LOG.info("addScrollTracker() - end;");
}

From source file:at.ac.tuwien.qse.sepm.gui.FullscreenWindow.java

@FXML
private void initialize() {
    this.stage = new Stage();
    this.scene = new Scene(this);

    stage.setScene(scene);//w w w  .j ava 2s. co  m

    image.setPreserveRatio(true);
    getChildren().add(0, image);

    hideButton.setOnAction((e) -> menu.setOpacity(0.0));
    menu.setOnMouseEntered(e -> menu.setOpacity(1.0));

    root.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(final KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.RIGHT) {
                bt_nextPressed(null);
            }
            if (keyEvent.getCode() == KeyCode.LEFT) {
                bt_previousPressed(null);
            }
            if (keyEvent.getCode() == KeyCode.ESCAPE) {
                stage.close();
            }
            if (keyEvent.getCode() == KeyCode.DIGIT1) {
                ratingPicker.setRating(Rating.BAD);
            }
            if (keyEvent.getCode() == KeyCode.DIGIT2) {
                ratingPicker.setRating(Rating.NEUTRAL);
            }
            if (keyEvent.getCode() == KeyCode.DIGIT3) {
                ratingPicker.setRating(Rating.GOOD);
            }
        }
    });

    ratingPicker.setRatingChangeHandler(this::handleRatingChange);
}

From source file:ambroafb.general.countcombobox.CountComboBox.java

private void addKeyListeners() {
    KeyCode plus = KeyCode.ADD;//from   w w w.  j  a  v  a2s  .  com
    KeyCode minus = KeyCode.SUBTRACT;
    setOnKeyPressed((KeyEvent event) -> {
        KeyCode eventKey = event.getCode();
        CountComboBoxItem selectedItem = getSelectionModel().getSelectedItem();
        if (selectedItem == null)
            return;
        CountComboBoxContainer selectedDrawItem = containers.get(selectedItem.getUniqueIdentifier());

        if (eventKey.equals(plus)) {
            selectedDrawItem.increaseNumberBy(counter);
        } else if (eventKey.equals(minus)) {
            selectedDrawItem.decreaseNumberBy(counter);
        }
        refreshButtonCell();
    });
}

From source file:com.jscriptive.moneyfx.ui.account.AccountFrame.java

public void keyTyped(KeyEvent event) {
    KeyCode keyCode = event.getCode();
    if (DELETE == keyCode) {
        deleteAccount();
    }
}

From source file:account.management.controller.expenseVoucherController.java

@Override
public void initialize(URL location, ResourceBundle resources) {

    new AutoCompleteComboBoxListener<>(this.location);
    this.location.setOnHiding((e) -> {
        Location a = this.location.getSelectionModel().getSelectedItem();
        this.location.setEditable(false);
        this.location.getSelectionModel().select(a);
    });/* www  .j  ava  2s  .c  om*/
    this.location.setOnShowing((e) -> {
        this.location.setEditable(true);
    });

    try {
        HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/locations").asJson();
        JSONArray array = res.getBody().getArray();
        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            this.location.getItems()
                    .add(new Location(obj.getInt("id"), obj.getString("name"), obj.getString("details")));
        }
        this.amount.setOnKeyReleased((e) -> {
            calculateTotal();
        });
    } catch (Exception e) {
    }

    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.save.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit expense voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        onSaveButtonClick(null);
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();

}

From source file:com.hengyi.japp.print.client.controller.MdController.java

@FXML
private void autoCompleteSapMara(KeyEvent ev) {
    try {/*from  w ww  . j a  v a  2 s. c o  m*/
        if (KeyCode.RIGHT.equals(ev.getCode())) {
            List<SapMara> sapMaras = md.getSapT001().autoCompleteSapMara(matnrField.getText());
            sapMaraListView.setItems(observableArrayList(sapMaras));
            sapMaraListView.setVisible(true);
            sapMaraListView.getSelectionModel().selectFirst();
        } else if (KeyCode.UP.equals(ev.getCode()) || KeyCode.DOWN.equals(ev.getCode())) {
            sapMaraListView.fireEvent(new KeyEvent(null, sapMaraListView, KeyEvent.KEY_PRESSED,
                    ev.getCharacter(), ev.getText(), ev.getCode(), false, false, false, false));
        } else if (KeyCode.ENTER.equals(ev.getCode())) {
            selectSapMara(sapMaraListView.getSelectionModel().getSelectedItem());
            sapMaraListView.setVisible(false);
        }
    } catch (Exception ex) {
        Util.alertDialog(ex);
    }
}

From source file:account.management.controller.POVoucherController.java

/**
 * Initializes the controller class.//from  www  .  ja  v  a2s  .c o  m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    balance.focusedProperty().addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue) {
                    Platform.runLater(new Runnable() {

                        @Override
                        public void run() {
                            balance.requestFocus();
                            balance.selectAll();
                        }
                    });

                }
            });
    this.container.getChildren().remove(0);
    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.total_price.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit deposit voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        try {
                            onSubmitButtonClick(null);
                        } catch (ParseException ex) {
                            Logger.getLogger(SalaryVoucherController.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        }
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();
}