I’m creating this typical graphs software where on each click you add a node, on Shift+Click on nodes you draw a vertex, etc. So I want to create some Mouse-Key combinations for triggering algorithms. For example, an Alt+K+Click event turns into the Kruskal graph ….
So far I’ve done:
root.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
if (t.isAltDown()) {
root.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent k) {
System.out.println(k.getText());
}
.....
.....
}
I got to a “scanning” buffer of keys but I don’t know how to stop it, k.consume isn’t working …
If you add the action that you want to perform as an ActionListener to a MenuItem, you can use the MenuItem accelerator property to specify a key combination that will trigger it. Some good examples at: http://thierrywasyl.wordpress.com/2012/08/01/keyboard-shortcuts-and-mnemonic-in-javafx/