From 278fb65852ccc0fa900e860221fbd74e87e4f6c7 Mon Sep 17 00:00:00 2001 From: Jessica Syder Date: Thu, 31 Aug 2017 22:39:19 +1200 Subject: [PATCH] Pressing ESC cancels the selected command's key from being replaced - focus is shifted away on esc - focus is shifted away after successful change #story[1197] --- .../visualiser/Controllers/KeyBindingsController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java b/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java index 621e91ef..aa8cf66f 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java @@ -4,6 +4,7 @@ import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.ListView; +import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.layout.AnchorPane; import visualiser.gameController.Keys.ControlKey; @@ -112,8 +113,13 @@ public class KeyBindingsController { */ public void setKeyListener(){ anchor.addEventFilter(KeyEvent.KEY_PRESSED, event -> { + // if esc, cancel current button click + if (event.getCode() == KeyCode.ESCAPE){ + btnCancel.requestFocus(); + currentButton = null; + } // if a button was clicked - if (currentButton != null) { + else if (currentButton != null) { // check if a button is already mapped to this key for (int i = 1; i < lstKey.getItems().size(); i++) { Button button = (Button)lstKey.getItems().get(i); @@ -130,6 +136,7 @@ public class KeyBindingsController { currentButton.getId()); // remove current button selection currentButton = null; + btnCancel.requestFocus(); } event.consume(); });