我想在SWT Shell中检测关键事件 Alt + Tab 键。按Tab键时,必须按 Alt 键。 我已尝试使用以下内容,但未检测到 Alt + Tab 。
public static void main(String[] args)
{
Display display = new Display ();
final Shell shell = new Shell (display);
final Color green = display.getSystemColor (SWT.COLOR_GREEN);
final Color orig = shell.getBackground();
display.addFilter(SWT.KeyDown, new Listener() {
public void handleEvent(Event e) {
if(((e.stateMask & SWT.ALT) == SWT.ALT) && (e.keyCode == SWT.TAB))
{
System.out.println("From Display I am the Key down !!" );
}
}
});
shell.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
if(((e.stateMask & SWT.ALT) == SWT.ALT) && (e.keyCode == SWT.TAB))
{
shell.setBackground(orig);
System.out.println("Key up ALT +TAB Detact !!");
}
}
public void keyPressed(KeyEvent e) {
if(((e.stateMask & SWT.ALT) == SWT.ALT) && (e.keyCode == SWT.TAB))
{
shell.setBackground(green);
System.out.println("Key down ALT +TAB Detact!!");
}
}
});
shell.setSize (200, 200);
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}