Display has such a method:
Public void addfilter (INT eventtype, listener)
That is, add a global listener to the display. For example, the shortcut key Ctrl + A is defined for the program above.
The display filter is very powerful. You can monitor the CTRL + A event no matter which control the current focus is on.
If there are other controls on the interface that listen to this shortcut key, the listener in this display will be executed first than the listener of other controls.
The following code comes from
Http://www.vogella.de/articles/SWT/article.html
Define a global keylistener for your display
You can define a global keylistener on your display to listen globally to all key events as long as your application has focus. The following demonstrates this.
Package de. vogella. SWT. listener;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. Widgets. display;
Import org. Eclipse. SWT. Widgets. event;
Import org. Eclipse. SWT. Widgets. listener;
Import org. Eclipse. SWT. Widgets. shell;
Public class globallistener {
Public static void main (string [] ARGs ){
Display display = New Display ();
Shell shell = new shell (Display );
Shell. open ();
Display. addfilter (SWT. keydown, new listener (){
@ Override
Public void handleevent (event ){
Char c = event. character;
System. Out. println (C );
}
});
While (! Shell. isdisposed ()){
If (! Display. readanddispatch ())
Display. Sleep ();
}
}
}