Inside the KeyTyped
method, how do I tell if Backspace or Esc is being pressed?
Personally, I prefer to use the KeyPressed event for keys other than letters/numbers, as when you're typing the Backspace or Enter keys, nothing is actually being typed per say. Here's what I did that worked (make sure KeyCode and KeyEvent are imported from javafx.scene.input)!
MyTextArea.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
@Override
public void handle(KeyEvent event) {
if (event.getCode().equals(KeyCode.BACK_SPACE)){
System.out.println("Success");
}
}
});
Let me know if this worked for you :)