我想在SWT中捕获Shift + Left Mouse Up事件。我只想在按住Shift键并释放鼠标左键的情况下仅打印一些示例消息。
答案 0 :(得分:4)
倾听SWT.MouseUp
并将Event.stateMask
与SWT.SHIFT
进行比较,然后将Event.button
与1
进行比较。
public static void main(String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout());
Text text = new Text(shell, SWT.BORDER);
text.addListener(SWT.MouseUp, new Listener()
{
@Override
public void handleEvent(Event e)
{
if ((e.stateMask & SWT.SHIFT) != 0 && e.button == 1)
{
System.out.println("shift pressed and left mouse clicked");
}
}
});
shell.pack();
shell.open();
shell.layout(true, true);
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}