Capturing keys in SWT text

I have some problems to detect the keys pressed in a textbox.

That's my text class and then I also have two buttons:

text1 = new Text(shell, SWT.BORDER | SWT.NO_SCROLL | SWT.SINGLE);
text1.addListener(SWT.KeyUp, new Listener() {
  public void handleEvent(Event e) {
    e.doit = false;
    int i = e.stateMask + e.keyCode;
    text1.setText(Integer.toString(i));
  }
});

okayButton = new Button(shell, SWT.PUSH);
okayButton.setText("&OK");

cancelButton = new Button(shell, SWT.PUSH);
cancelButton.setText("&Abbrechen");

      

My problem is that global keys seem to be processed before my own handler. For example, if I press Alt + O, then the OK button is fired, but not my handler. Same effect by pressing escape.

How can I prevent the global shortcuts from being executed and only execute the native handleEvent method?

+3


source to share





All Articles