e858. 将键盘键和事件绑定

Posted borter

tags:

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

This example creates a number of keystrokes and adds them to the input map of a component. When a keystroke is added to an input map, an action name must be supplied. This action is invoked when the keystroke is pressed while the component has the focus.

    // Create some keystrokes and bind them all to the same action
    component.getInputMap().put(KeyStroke.getKeyStroke("F2"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("control A"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("shift F2"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke(‘(‘), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("button3 F"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("typed x"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("released DELETE"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("shift UP"), "actionName");
    
    // Add the action to the component
    component.getActionMap().put("actionName",
        new AbstractAction("actionName") {
            public void actionPerformed(ActionEvent evt) {
                process(evt);
            }
        }
    );

 

Related Examples

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

js组合键和单个键盘事件

js组合键和单个键盘事件

Atitit.android js 的键盘按键检测Back键Home键和Menu键事件

28-30 键盘事件

三个键盘事件的区别:

js 键盘事件(onkeydownonkeyuponkeypress)