Is there a way to detect a CTRL-click on a ToolItem? I want to distinguish between CTRL+Click and normal mouse click.
ToolBar toolbar= new ToolBar(parent, SWT.NONE);
ToolItem saveToolItem = new ToolItem(toolbar, SWT.PUSH);
...
saveToolItem.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
// if CTRL+Click {
// specialSave();
// } else
normalSave();
}));
The SelectionEvent
passed to the event (in e
in your code) has a stateMask
field including the modifier keys being pressed. The SWT.CTRL
constant for Ctrl.
So:
if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
Tests for the Ctrl key being pressed
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.