📅  最后修改于: 2022-03-11 14:52:49.106000             🧑  作者: Mango
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.KeyCode;
btn.setOnKeyPressed(new EventHandler() {
@Override
public void handle(KeyEvent k) {
if (k.getCode().equals(KeyCode.ENTER)) {
doSomething();
}
}
});