You can find example of such key post event, like in this class
Those posts are using the dispatchEvent() function
public void mousePressed(MouseEvent event) {
KeyboardButton key = getKey(event.getX(), event.getY());
[...]
KeyEvent ke;
Component source = Component.getFocusComponent();
lastPressed = key;
lastSource = source;
key.setPressed(true);
if(source != null) {
if((key == k_accent || key == k_circle) && (lastKey instanceof KeyboardButtonTextJapanese)) {
int accent = ((KeyboardButtonTextJapanese)lastKey).getAccent();
if(accent >= 1 && key == k_accent) {
/*
** First send a backspace to delete the previous character, then send the character with the accent.
*/
source.dispatchEvent(new KeyEvent(source, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, k_backspace.getKeyEvent(), k_backspace.getKeyChar()));
source.dispatchEvent(new KeyEvent(source, KeyEvent.KEY_TYPED, System.currentTimeMillis(), 0, k_backspace.getKeyEvent(), k_backspace.getKeyChar()));