java - Control is entering multiple times for single keypress -


i have piece of code in java swing disable keystrokes. when press key once control enters code multiple times.

i attach code:

keyboardfocusmanager.getcurrentkeyboardfocusmanager()             .addkeyeventdispatcher(new keyeventdispatcher() {                 public boolean dispatchkeyevent(keyevent ke) {                     if (keyboardfocusmanager.getcurrentkeyboardfocusmanager().getfocusowner() instanceof jtextarea) {                         if (ke.getid() == keyevent.key_pressed) {                             int key = ke.getkeycode();                             if (key == keyevent.vk_up || key == keyevent.vk_down) {                                 arrowkey = true;                                 ke.consume();                             }                         }                         if (ke.getid() == keyevent.key_typed && arrowkey) ke.consume();                         if (ke.getid() == keyevent.key_released) arrowkey = false;                     }                     return false;                 }             }); 


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -