How to create a JavaFX KeyCombination with three or more keys?
The Problem is that the KeyEvent only has one KeyCode. So its not possible to let an KeyCombination match multiple KeyCodes.
But you can try something like this:
Store all pressed Keys into an List (maybe you have to use event Listener for keyPressed)
@Override
public void initialize(URL location, ResourceBundle resources) {
scene.setOnKeyPressed((event) -> {
codes.add(event.getCode());
});
scene.setOnKeyReleased((event) -> {
codes.remove(event.getCode());
});
}
Write your own KeyCombi class
private class MultipleKeyCombi extends KeyCombination {
private List<KeyCode> neededCodes;
public MultipleKeyCombi(KeyCode... codes) {
neededCodes = Arrays.asList(codes);
}
@Override
public boolean match(KeyEvent event) {
return codes.containsAll(neededCodes);
}
}
And use it in your Menu.
item.setAccelerator(new MultipleKeyCombi(KeyCode.A, KeyCode.S));
This should work.
I wrote a Prototype here Bitbucket Repo