java - Detect the Windows key modifier -
how can detect windows key
modifier keyevent
? have add code:
textfield.addkeylistener(new keyadapter() { public void keyreleased(keyevent e) { if ((e.getkeycode() & keyevent.vk_escape) == keyevent.vk_escape) { textfield.settext(""); } } });
but problem is, when use windows zoom
, try exit using win + escape
, if focus in textfield
, content clears. i've tried filter e.getmodifiersex()
, returns 0
. way i've found detect whether windows
pressed or not, create boolean
field , change it's value when windows
pressed/released.
so, there way windows
key pressure state keyevent
escape released
event?
the way used myself:
abstractaction escapeaction = abstractaction() { public void actionperfomed(actionevent e) { settext(""); } } textfield.addcaretlistener(new caretlistener() { @override public void caretupdate(caretevent e) { if (textfield.gettext() == null || textfield.gettext().isempty()) { textfield.getactionmap().remove("escape"); textfield.getinputmap().remove(keystroke.getkeystroke(keyevent.vk_escape, 0)); } else { textfield.getactionmap().put("escape", escapeaction); textfield.getinputmap().put(keystroke.getkeystroke(keyevent.vk_escape, 0), escapeaction); } } });
Comments
Post a Comment