PDA

View Full Version : trapping ESC key in textfield - how ?



bobpardoe
30 Jun 2010, 5:19 AM
The Field class docs say a SpecialKey event is fired when any key related to navigation is pressed.

I can see the event being fired via fireEvent() but thats the last we see of it.

All the other documented events have an onKey... method, but not the special keys.

I want to trap the use of the ESC key so I can do some additional processing. I also need to stop it bubbling up to the window closure when isOnEsc(true) is set.

I have tried adding my own KeyListener


txtFilter.addKeyListener(new KeyListener()
{
@Override
public void componentKeyUp(ComponentEvent event)
{
super.componentKeyUp(event);

if (event.getKeyCode() == KeyCodes.KEY_ESCAPE)
{
event.cancelBubble();
onGoBack();
}
}
});also tried this


txtFilter.addListener(Events.SpecialKey, new Listener<FieldEvent>()
{
public void handleEvent(FieldEvent fe)
{
Log.debug(" handleEvent");

if (fe.isSpecialKey())
{
Log.debug(" handleEvent - special");
}

}
});Any ideas pls ?

Thanks

BOb