سؤال

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));
هل كانت مفيدة؟

المحلول

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));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top