如何更改此代码以接受任何键(不仅是 F5)并打印该键?
component.getRootPane().getInputMap(JRootPane.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), "F5 Pressed");
component.getRootPane().getActionMap().put("F5 Pressed", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// Code here
}
});