Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect META key press during Drag and Drop on OSX

There is a bug in Java 6/7 on OSX where during Drag and Drop operations, it ignores the META (CMD) key. (Ctrl key works just fine on Windows, Ctrl key is also ignores on OSX) I REALLY need to have this working.

See: Java Drag and drop on OS X reports Move instead of Copy

I tried adding a KeyEventDispatcher listener to the KeyboardFocusManager, but that isn't called during a Drag operation.

Nor does the processKeyEvent() method of the parent JPanel ever get invoked.

So, is there any place where I can put a hook to detect META key presses?

like image 497
CasaDelGato Avatar asked Jul 27 '16 19:07

CasaDelGato


1 Answers

On the DragGestureEvent you can get the modifiers. e.getTriggerEvent().getModifiersEx() javadocs state:

Extended modifiers represent the state of all modal keys, such as ALT, CTRL, META, and the mouse buttons just after the event occurred.

This code worked for me on OSX:

public void dragGestureRecognized(DragGestureEvent e)
{
    boolean isMetaDown = InputEvent.META_DOWN_MASK == (e.getTriggerEvent().getModifiersEx() & InputEvent.META_DOWN_MASK));
    System.out.println("metaDown:"+isMetaDown);
}
like image 168
Jayfray Avatar answered Nov 08 '22 07:11

Jayfray