简体   繁体   中英

Detect CTRL+Click on SWT ToolItem

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM