Question

I have a java program, and I want to keybind just the meta key, not another key with a meta mask. Is there any way to do this? Here's my attempt that failed:

getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_META, 0), "meta-down");
getActionMap().put("meta-down", new MetaDownAction(this));
Was it helpful?

Solution

So I found out that the way to do this is to detect a meta key mask too, as depicted below.

getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_META, InputEvent.META_DOWN_MASK), "meta-down");
getActionMap().put("meta-down", new MetaDownAction(this));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top