1import javafx.event.ActionEvent;
2import javafx.event.EventHandler;
3import javafx.scene.input.KeyEvent;
4import javafx.scene.input.KeyCode;
5
6btn.setOnKeyPressed(new EventHandler<KeyEvent>() {
7 @Override
8 public void handle(KeyEvent k) {
9 if (k.getCode().equals(KeyCode.ENTER)) {
10 doSomething();
11 }
12 }
13});