e860. 列出组件绑定的键盘键

Posted borter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了e860. 列出组件绑定的键盘键相关的知识,希望对你有一定的参考价值。

This example demonstrates how to list all the key bindings in a component. Text components have an additional set of key bindings called a keymap. See e1005 列出JTextComponent中键盘映射绑定的键 for an example on how to list those key bindings.

    // 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 e859 将键盘事件和字符串对应
            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]);
            }
        }
    }

 

Related Examples

以上是关于e860. 列出组件绑定的键盘键的主要内容,如果未能解决你的问题,请参考以下文章

C ++绑定键盘键:遍历所有虚拟键?

中兴ZXV10 B760E IPTV智能机顶盒 adb 破解安装软件

如何使用键盘上的 Enter 键登录网站? [关闭]

打开新片段时取消绑定/关闭所有 cameraX 组件

绑定数字键(数字小键盘)

按下返回键时隐藏软键盘