This is a great question! (By which, I mean Amy's question, not mine!)
I wrote this sample exam problem before trying it myself, thinking that it would be a straightforward thing to transfer over some knowledge from your team projects, where you are using keyboard input for paddle or straight keys.
However, it's not quite so straightforward.
In JavaFX it turns out that a canvas object doesn't have keyboard "focus" by default, and can't receive the key events.
The easiest way to remedy this is probably to do the following commands:
drawingCanvas.setFocusTraversable(true);
drawingCanvas.addEventFilter(MouseEvent.ANY, (e) -> drawingCanvas.requestFocus());
drawingCanvas.setOnKeyPressed(e -> System.out.println(e));
This: 1) allows the canvas to get keyboard focus, and 2) actually puts the keyboard focus on the canvas any time that ANY mouse event happens (clicking, or even moving the mouse cursor over the canvas). The last line just prints out the key event, but should probably be replaced with something like:
drawingCanvas.setOnKeyPressed(e -> deleteAction());
where you implement a deleteAction() method in your controller.
Note: There are other ways to work around this as well, such as setting the onKeyPressed on the Scene
object, instead instead of the canvas, but it's a bit tricky to access the Scene during the initialize method, because the components haven't been added to the Scene yet. Thus, you can do something like:
Platform.runLater(() -> drawingCanvas.getScene().setOnKeyPressed(e -> System.out.println(e)));
which schedules the key event handler to get set on the Scene after the root pane has been added to the scene.
In any case, I apologize that this was a bit trickier than expected. If something similar comes up on the real exam, at least you can come back to this Q&A question!