I have written an SWT UI which has a primary function of displaying text in a StyledText control. I want to add a handler for Ctrl+F so that when that shortcut is pressed the focus is set to a search box. I have tried using the following code to detect the keypress.
sWindow = new Shell();
...
sWindow.getDisplay().addFilter(SWT.KeyDown, new Listener()
{
@Override
public void handleEvent(Event e)
{
System.out.println("Filter-ctrl: " + SWT.CTRL);
System.out.println("Filter-mask: " + e.stateMask);
System.out.println("Filter-char: " + e.character);
}
});
I was expecting that when I pressed Ctrl+f I would see the following output:
Filter-ctrl: 262144
Filter-mask: 262144
Filter-char: f
However, in practice I actually see the following.
Filter-ctrl: 262144
Filter-mask: 262144
Filter-char: <unprintable char - displayed as a box in eclipse console>
I have two questions:
Is Display.addFilter(...) the best way to add a glbal shortcut? I tried Display.addListener(...) but this didn't receive any events at all.