Je voudrais créer un gestionnaire d'événements qui écoute la combinaison de touches "Hold Ctr + C". Est-ce que "si ((… == Contrôle) && (… == C))" ne fonctionne pas?
textField.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { public void handle(KeyEvent event) { if((event.getCode() == KeyCode.CONTROL) && (event.getCode() == KeyCode.C)) { System.out.println("Control pressed"); } }; });
Pour la pression de plusieurs touches, vous devez définir la propriété de combinaison de touches. Essayez ceci …
textfield.getScene().getAccelerators().put( new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY), new Runnable() { @Override public void run() { //condition here of you that want you want to achive. textfield.requestFocus(); } } );
Vous pouvez essayer cette solution complète, cela a fonctionné pour moi;
final KeyCombination keyCombinationShiftC = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN);
. . .
textField.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (keyCombinationShiftC.match(event)) { logger.info("CTRL + C Pressed"); } } });
. . .
Cela serait utile. KeyCombination.
final KeyCombination keyComb1=new KeyCodeCombination(KeyCode.C,KeyCombination.CONTROL_DOWN);