diff --git a/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java b/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java index 528f3869..621e91ef 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/KeyBindingsController.java @@ -114,7 +114,15 @@ public class KeyBindingsController { anchor.addEventFilter(KeyEvent.KEY_PRESSED, event -> { // if a button was clicked if (currentButton != null) { - System.out.println("button is clicked"); + // 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); + // update buttons text and remove key binding from command + if (button.getText() == event.getCode().toString()) { + button.setText(""); + newKeyFactory.updateKey(button.getId(), button.getId()); + } + } // update text on the button currentButton.setText(event.getCode().toString()); // update the control key