@Override public void actionPerformed(ActionEvent e) { final NavBarKeyboardCommand cmd = NavBarKeyboardCommand.fromString(e.getActionCommand()); if (cmd != null) { switch (cmd) { case LEFT: myPanel.moveLeft(); break; case RIGHT: myPanel.moveRight(); break; case HOME: myPanel.moveHome(); break; case END: myPanel.moveEnd(); break; case DOWN: myPanel.moveDown(); break; case UP: myPanel.moveDown(); break; case ENTER: myPanel.enter(); break; case ESCAPE: myPanel.escape(); break; case NAVIGATE: myPanel.navigate(); break; } } }
@Override public void keyPressed(final KeyEvent e) { if (!(e.isAltDown() || e.isMetaDown() || e.isControlDown() || myPanel.isNodePopupActive())) { if (!Character.isLetter(e.getKeyChar())) { return; } final IdeFocusManager focusManager = IdeFocusManager.getInstance(myPanel.getProject()); final ActionCallback firstCharTyped = new ActionCallback(); focusManager.typeAheadUntil(firstCharTyped); myPanel.moveDown(); //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { public void run() { try { final Robot robot = new Robot(); final boolean shiftOn = e.isShiftDown(); final int code = e.getKeyCode(); if (shiftOn) { robot.keyPress(KeyEvent.VK_SHIFT); } robot.keyPress(code); robot.keyRelease(code); // don't release Shift firstCharTyped.setDone(); } catch (AWTException ignored) { } } }); } }