onkeypress change key

Hey everyone,

I’m trying to chance the key when a certain key is pressed with the following code:

private void keyDownEvent(KeyDownEvent e, TextField textField){
	Key key =e.getCode().get();
	Key key2 = e.getKey();
	if(key.equals(Key.SPACE)){Key.SPACE.
		numberField.setValue(textField.getValue()+",");
		//method doesn't exist..
		e.setkey
	}
}

Unfortunately more things are going wrong here. The if is never true, it doesn’t matter if I use the key or key2 variable here.
Then there is the thing of change the character that’s being added to as tring somewhere. (could also be in the middle of the string…).

Does anyone know how to handle this?

Kind regards,

So now I finally got the key I want, but I want to switch it to the comma without using setvalue (as that triggers on value change and that deletes everything thats typed inside the textfield) see:

private void keyDownEvent(KeyDownEvent e, TextField numberField){
	List<String> pressedkey = e.getCode().get().getKeys();
	List<String> spaceKeys =Key.NUMPAD_DECIMAL.getKeys();
	for(String key : pressedkey){
		if(spaceKeys.contains(key)){
		//need this to work
			e.setkey(",");
		}
	}
}