ListKeyBinds

// List keystrokes in the WHEN_FOCUSED input map of the component
InputMap map = component.getInputMap(JComponent.WHEN_FOCUSED);
list(map, map.keys());
// List keystrokes in the component and in all parent input maps
list(map, map.allKeys());

// List keystrokes in the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT input map of the component
map = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
list(map, map.keys());
// List keystrokes in all related input maps
list(map, map.allKeys());

// List keystrokes in the WHEN_IN_FOCUSED_WINDOW input map of the component
map = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
list(map, map.keys());
// List keystrokes in all related input maps
list(map, map.allKeys());

public static void list(InputMap map, KeyStroke[] keys) {
    if (keys == null) {
        return;
    }
    for (int i=0; i<keys.length; i++) {
        // This method is defined in Converting a KeyStroke to a String
        String keystrokeStr =  keyStroke2String(keys[i]);

        // Get the action name bound to this keystroke
        while (map.get(keys[i]) == null) {
            map = map.getParent();
        }
        if (map.get(keys[i]) instanceof String) {
            String actionName = (String)map.get(keys[i]);
        } else {
            Action action = (Action)map.get(keys[i]);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.