I have a file .fxml
where I have defined a control PasswordField
and an event KeyPressed
:
<PasswordField fx:id="clave" onKeyPressed="#teclaPulsada" prefWidth="170.0" />
I want to prevent someone from pasting a copied key and thus force it to be typed. I'm trying the following code to detect the control or command key (depending on whether it's win or mac) but I don't know how to detect the v key (control/command + v) at the same time
@FXML
void teclaPulsada(KeyEvent keyEvent) {
if (keyEvent.getCode() == KeyCode.COMMAND) {
System.out.println("pulsado command");
keyEvent.consume();
if (keyEvent.getText() == "v") {
System.out.println("pulsada la v");
keyEvent.consume();
}
}
}
You must use a listener for an instance of the class
KeyCodeCombination
: