// keyCode = KeyEvent VK_... static void registerKey(JComponent c, int keyCode, S name, final O r) { Action action = abstractAction(name, r); KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, 0); c.getActionMap().put(name, action); c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, name); } static void registerKey(JFrame frame, int keyCode, S name, final O r) { registerKey(frame.getRootPane(), keyCode, name, r); }