@Override public boolean dispatchKeyEvent(KeyEvent e) { int keyCode = e.getKeyCode(); if (e.getID() == KEY_PRESSED) { try { handleKeyPressed(keyCode); } catch (IOException | InterruptedException e1) { e1.printStackTrace(); } } else if (e.getID() == KEY_RELEASED) { handleKeyReleased(keyCode); } return true; }