Scene scene = this.root.getScene(); scene.addEventHandler(KeyEvent.KEY_PRESSED, event -> gameManager.restartGame(event)); scene.removeEventHandler(KeyEvent.KEY_PRESSED, event -> gameManager.restartGame(event)); With this code, when you start the game, the idea is that the action should disappear when you press a button. Without adding eventHandler, the game does not respond, but it does not remove it. What could be wrong?
scene and stage are always the same